list.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div class="app-container">
  3. 机构列表
  4. </div>
  5. </template>
  6. <script>
  7. import { parseTime } from '@/utils'
  8. import { fetchKeywordList, joinKeywordLibrary } from '@/api/library/keyword'
  9. import { export_json_to_excel } from '@/vendor/Export2Excel'
  10. export default {
  11. data() {
  12. const pickerOptions = {
  13. shortcuts: [
  14. {
  15. text: '近1年',
  16. onClick(picker) {
  17. const end = new Date()
  18. const start = new Date()
  19. start.setTime(start.getTime() - 3600 * 1000 * 24 * 365)
  20. picker.$emit('pick', [start, end])
  21. }
  22. },
  23. {
  24. text: '近半年',
  25. onClick(picker) {
  26. const end = new Date()
  27. const start = new Date()
  28. start.setTime(start.getTime() - 3600 * 1000 * 24 * 183)
  29. picker.$emit('pick', [start, end])
  30. }
  31. },
  32. {
  33. text: '近1月',
  34. onClick(picker) {
  35. const end = new Date()
  36. const start = new Date()
  37. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  38. picker.$emit('pick', [start, end])
  39. }
  40. },
  41. {
  42. text: '近1周',
  43. onClick(picker) {
  44. const end = new Date()
  45. const start = new Date()
  46. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  47. picker.$emit('pick', [start, end])
  48. }
  49. },
  50. {
  51. text: '昨天',
  52. onClick(picker) {
  53. const end = new Date()
  54. const start = new Date()
  55. start.setTime(start.getTime() - 3600 * 1000 * 24)
  56. picker.$emit('pick', [start, end])
  57. }
  58. }
  59. ]
  60. }
  61. return {
  62. isLoading: true,
  63. time: '',
  64. listQuery: {
  65. keyword: '',
  66. beginTime: '',
  67. endTime: '',
  68. labelStatus: '',
  69. searchTimeCode: '',
  70. fromSearch: '',
  71. pageNum: 1,
  72. pageSize: 10
  73. },
  74. pickerOptions,
  75. list: [],
  76. total: 0,
  77. currentList: [],
  78. searchDialog: false,
  79. visibleKeyword: ''
  80. }
  81. },
  82. computed: {
  83. disabled() {
  84. return this.currentList.length === 0
  85. }
  86. },
  87. created() {
  88. this.getList()
  89. },
  90. methods: {
  91. // 获取关键词列表
  92. getList() {
  93. this.listQuery.pageNum = 1
  94. if (this.time && this.time.length > 0) {
  95. this.listQuery.beginTime = this.time[0]
  96. this.listQuery.endTime = this.time[1]
  97. } else {
  98. this.listQuery.beginTime = ''
  99. this.listQuery.endTime = ''
  100. }
  101. this.fetchKeywordList()
  102. },
  103. // 获取关键词列表
  104. async fetchKeywordList() {
  105. try {
  106. this.isLoading = true
  107. const res = await fetchKeywordList(this.listQuery)
  108. this.list = res.data.results
  109. this.total = res.data.totalRecord
  110. this.isLoading = false
  111. } catch (error) {
  112. console.log(error)
  113. }
  114. },
  115. // 添加到标签库
  116. async handleAddLibrary(row) {
  117. try {
  118. await this.$confirm('确定将所选标签加入到标签库?', {
  119. confirmButtonText: '确定',
  120. cancelButtonText: '取消',
  121. type: 'warning'
  122. })
  123. this.addLibrarySubmit(row)
  124. } catch (error) {
  125. this.$message.info('已取消操作')
  126. }
  127. },
  128. // 添加到标签库提交
  129. async addLibrarySubmit(row) {
  130. const keywords = row instanceof Event ? this.currentList : [].concat(row)
  131. const ids = keywords.map((item) => item.id).join(',')
  132. try {
  133. await joinKeywordLibrary({ id: ids })
  134. this.$message.success('添加关键词库成功')
  135. keywords.forEach((item) => {
  136. item.labelStatus = 1
  137. })
  138. } catch (error) {
  139. console.log(error)
  140. }
  141. },
  142. // 选中列表项
  143. handleSelectionChange(current) {
  144. this.currentList = current
  145. },
  146. // 去搜索
  147. handleSearch(keyword) {
  148. this.visibleKeyword = keyword
  149. this.searchDialog = true
  150. },
  151. // 导出
  152. async handleExport() {
  153. try {
  154. await this.$confirm('确定将所选标签导出为xlsx?', {
  155. confirmButtonText: '确定',
  156. cancelButtonText: '取消',
  157. type: 'warning'
  158. })
  159. // 导出数据格式化
  160. const filterVal = ['index', 'keyword', 'frequency', 'searchTime', 'labelStatus']
  161. const data = this.formatJson(filterVal, this.currentList.slice(0))
  162. export_json_to_excel({
  163. header: ['序号', '标签', '搜索次数', '最近搜索时间', '标签库状态'],
  164. data,
  165. filename: '关键词列表'
  166. })
  167. } catch (error) {
  168. this.$message.info('已取消导出操作')
  169. }
  170. },
  171. formatJson(filterVal, jsonData) {
  172. return jsonData.map((v, index) =>
  173. filterVal.map((key) => {
  174. if (['searchTime'].includes(key)) {
  175. return parseTime(v[key])
  176. }
  177. if (key === 'index') return index + 1
  178. if (key === 'labelStatus') {
  179. const t = ['未添加', '已添加', '导入']
  180. return t[v[key]]
  181. }
  182. return v[key]
  183. })
  184. )
  185. },
  186. indexMethod(index) {
  187. return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
  188. }
  189. }
  190. }
  191. </script>
  192. <style></style>