downloads.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="content">
  3. <div class="downloads">
  4. <div class="download-types noScroll">
  5. <div class="searchType">
  6. <input type="text" placeholder="在此处搜索文件" v-model="searchKey" @input="filterTypeChangeHandle" >
  7. <span class="close" @click="clearSearchText" >
  8. x
  9. </span>
  10. </div>
  11. <div class="d-type"
  12. v-for="item in filterTypes"
  13. :key="item.key"
  14. @click="switchType(item.key)"
  15. >
  16. {{item.title}}
  17. </div>
  18. </div>
  19. <div class="download-type-items">
  20. <div class="title">
  21. <span class="text-m text-b">[</span>
  22. <span class="mark-gold">{{nowTitle}}</span>
  23. <span class="text-b">]</span>
  24. 资料下载
  25. </div>
  26. <div class="d-type-item"
  27. v-for="(item,i) in subItems"
  28. :key="nowKey+'_'+i"
  29. >
  30. <a :href="item.src" target="_blank">
  31. <span class="file">
  32. <svg-icon class="icon" :icon-class="item.icon?item.icon:'unknownFile'"></svg-icon>
  33. {{item.title}}
  34. </span>
  35. <span class="time">
  36. {{timestampToTime(item.add_time)}}
  37. </span>
  38. </a>
  39. </div>
  40. </div>
  41. </div>
  42. <div class="downloads-more">
  43. <div class="more-text">
  44. 没有找到您需要的资料?请
  45. 联系我们,我们将竭诚为您服务。
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import langMap from "@/map/langMap";
  52. import {timestampToTime} from "@/until/time";
  53. export default {
  54. name: "downloads",
  55. props: {
  56. lang:{
  57. default: langMap.lang.cn
  58. },
  59. downloads:{
  60. default: []
  61. }
  62. },
  63. data(){
  64. return {
  65. langType: langMap.lang,
  66. searchKey: '',
  67. filterTypes: [],
  68. subItems: [],
  69. nowTitle: '',
  70. nowKey: '',
  71. waitTimer: null,
  72. }
  73. },
  74. created(){
  75. this.filterTypes = this.downloads;
  76. this.switchType(this.downloads[0].key);
  77. },
  78. watch:{
  79. downloads(){
  80. this.filterTypeChangeHandle();
  81. }
  82. },
  83. methods:{
  84. timestampToTime(){
  85. return timestampToTime(...arguments);
  86. },
  87. switchType(key){
  88. if (this.nowKey !== key){
  89. this.$root.$emit('loadDownloadItem',key);
  90. this.nowKey = key;
  91. let items = this.downloads.find(item=>item.key === key);
  92. console.log(items);
  93. if(!items.length){
  94. // 如果没有则等下一tick重新获取数据
  95. setTimeout(()=>{
  96. let items = this.downloads.find(item=>item.key === key);
  97. this.subItems = items?items.subItems:[];
  98. this.nowTitle = `${items?items.title:''}`;
  99. },300);
  100. }else{
  101. this.subItems = items?items.subItems:[];
  102. this.nowTitle = `${items?items.title:''}`;
  103. }
  104. }
  105. },
  106. filterTypeChangeHandle(){
  107. console.log('触发更新')
  108. // 等待700毫秒,防抖
  109. if (this.waitTimer){
  110. clearTimeout(this.waitTimer);
  111. }
  112. this.waitTimer = setTimeout(()=>{
  113. this.waitTimer = null;
  114. let key = this.searchKey;
  115. if (key){
  116. // 忽略大小写
  117. // key = key.toLowerCase();
  118. this.filterTypes = this.downloads.filter(item=> item.title.indexOf(key) !== -1);
  119. }else{
  120. this.filterTypes = this.downloads;
  121. }
  122. },700);
  123. },
  124. clearSearchText(){
  125. this.searchKey = '';
  126. this.filterTypeChangeHandle();
  127. }
  128. },
  129. }
  130. </script>
  131. <style scoped>
  132. .downloads{
  133. width: 100%;
  134. height: 100%;
  135. display: flex;
  136. flex-direction: row;
  137. justify-content: space-between;
  138. align-items: flex-start;
  139. }
  140. .download-types{
  141. width: 20%;
  142. height: 100%;
  143. display: flex;
  144. flex-direction: column;
  145. justify-content: flex-start;
  146. align-items: center;
  147. border-right: 1px solid #e5e5e5;
  148. overflow: auto;
  149. }
  150. .download-types .searchType{
  151. width: 100%;
  152. height: 40px;
  153. display: flex;
  154. flex-direction: row;
  155. justify-content: center;
  156. align-items: center;
  157. position: relative;
  158. font-size: 0.95rem;
  159. }
  160. .download-types .searchType input{
  161. width: 100%;
  162. height: 30px;
  163. border: 1px solid #e5e5e5;
  164. border-radius: 5px;
  165. padding: 0 10px;
  166. outline: none;
  167. position: relative;
  168. }
  169. .download-types .searchType .close{
  170. width: 20px;
  171. height: 20px;
  172. display: flex;
  173. flex-direction: row;
  174. justify-content: center;
  175. align-items: center;
  176. margin-left: 10px;
  177. cursor: pointer;
  178. position: absolute;
  179. right: 10px;
  180. color: #c54949;
  181. }
  182. .download-types .searchType .close:hover{
  183. color: #ff0000;
  184. font-size: 1.15rem;
  185. }
  186. .d-type{
  187. width: 100%;
  188. height: 40px;
  189. display: flex;
  190. flex-direction: row;
  191. justify-content: center;
  192. align-items: center;
  193. border-bottom: 1px solid #e5e5e5;
  194. cursor: pointer;
  195. }
  196. .d-type:hover{
  197. background-color: #f5f5f5;
  198. }
  199. .download-type-items{
  200. width: 80%;
  201. height: 100%;
  202. display: flex;
  203. flex-direction: column;
  204. justify-content: flex-start;
  205. align-items: flex-start;
  206. padding: 10px;
  207. }
  208. .download-type-items .title{
  209. width: 100%;
  210. height: 40px;
  211. display: flex;
  212. flex-direction: row;
  213. justify-content: flex-start;
  214. align-items: center;
  215. font-size: 1.2rem;
  216. font-weight: bold;
  217. color: #333333;
  218. }
  219. .download-type-items .d-type-item{
  220. width: 100%;
  221. height: 100%;
  222. display: flex;
  223. flex-direction: column;
  224. justify-content: flex-start;
  225. align-items: flex-start;
  226. }
  227. .download-type-items .d-type-item a{
  228. width: 100%;
  229. height: 40px;
  230. display: flex;
  231. flex-direction: row;
  232. justify-content: space-between;
  233. align-items: center;
  234. border-bottom: 1px solid #e5e5e5;
  235. text-decoration: none;
  236. color: #333333;
  237. cursor: pointer;
  238. padding: 0 10px;
  239. box-sizing: border-box;
  240. }
  241. .download-type-items .d-type-item a:hover{
  242. background-color: #ce5e5e;
  243. color: #ffffff;
  244. }
  245. .download-type-items .d-type-item a .file{
  246. width: calc(100% - 200px);
  247. height: 100%;
  248. display: flex;
  249. flex-direction: row;
  250. justify-content: flex-start;
  251. align-items: center;
  252. }
  253. .download-type-items .d-type-item a .file .icon{
  254. width: 20px;
  255. height: 20px;
  256. display: flex;
  257. flex-direction: row;
  258. justify-content: center;
  259. align-items: center;
  260. margin-right: 10px;
  261. }
  262. .download-type-items .d-type-item a .time{
  263. width: 200px;
  264. height: 100%;
  265. display: flex;
  266. flex-direction: row;
  267. justify-content: flex-end;
  268. align-items: center;
  269. }
  270. .downloads-more{
  271. width: 100%;
  272. height: 100%;
  273. display: flex;
  274. flex-direction: column;
  275. justify-content: flex-start;
  276. align-items: flex-start;
  277. margin-top: 20px;
  278. cursor: default;
  279. }
  280. </style>