DataSource.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <el-row>
  3. <el-row>
  4. <el-form :inline="true" :model="searchForm" class="demo-form-inline">
  5. <el-form-item>
  6. <el-select v-model="searchForm.status" placeholder="状态" @change="search">
  7. <el-option label="未下载" value="1" />
  8. <el-option label="下载中" value="2" />
  9. <el-option label="已下载" value="3" />
  10. <el-option label="已发布" value="4" />
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item>
  14. <el-input v-model="searchForm.title" placeholder="" />
  15. </el-form-item>
  16. <el-form-item>
  17. <el-button size="mini" type="warning" @click="search">查询</el-button>
  18. </el-form-item>
  19. </el-form>
  20. <el-form :inline="true" class="demo-form-inline">
  21. <el-form-item>
  22. <el-button size="mini" type="danger" @click="deleteMultiple">删除多行</el-button>
  23. </el-form-item>
  24. </el-form>
  25. <el-table
  26. ref="multipleTable"
  27. :data="dataList"
  28. border
  29. style="width: 100%"
  30. @selection-change="handleSelectionChange"
  31. >
  32. <el-table-column
  33. type="selection"
  34. />
  35. <el-table-column
  36. prop="site"
  37. label="Site"
  38. />
  39. <el-table-column
  40. prop="title"
  41. label="Name"
  42. width="400px"
  43. >
  44. <template slot-scope="scope">
  45. <a :href="scope.row.pageUrl" style="text-decoration-line: none" target="_blank">
  46. <el-tooltip
  47. :content="scope.row.title"
  48. raw-content
  49. placement="top-start"
  50. >
  51. <span v-if="scope.row.title.length <= 60">
  52. {{ scope.row.title }}
  53. </span>
  54. <span v-else>
  55. {{ scope.row.title.substr(0, 55) + "..." }}
  56. </span>
  57. </el-tooltip>
  58. </a>
  59. </template>
  60. </el-table-column>
  61. <el-table-column
  62. prop="magnetUri"
  63. label="Link"
  64. >
  65. <template slot-scope="scope">
  66. <a :href="scope.row.magnetUri">
  67. <span class="el-icon-link" />
  68. </a>
  69. </template>
  70. </el-table-column>
  71. <el-table-column
  72. prop="size"
  73. label="Size"
  74. />
  75. <el-table-column
  76. prop="pubDate"
  77. label="Date"
  78. />
  79. <el-table-column
  80. prop="status"
  81. label="Status"
  82. >
  83. <template slot-scope="scope">
  84. <el-tag v-if="scope.row.status === 1" :type="'warning'" disable-transitions>
  85. 未下载
  86. </el-tag>
  87. <el-tag v-else-if="scope.row.status === 2" :type="'success'" disable-transitions>
  88. 下载中
  89. </el-tag>
  90. <el-tag v-else-if="scope.row.status === 3" :type="'danger'" disable-transitions>
  91. 已下载
  92. </el-tag>
  93. <el-tag v-else :type="'danger'" disable-transitions>
  94. 已发布
  95. </el-tag>
  96. </template>
  97. </el-table-column>
  98. <el-table-column
  99. label="操作"
  100. >
  101. <template slot-scope="scope">
  102. <el-button
  103. size="mini"
  104. @click="cache(scope.row)"
  105. >缓存</el-button>
  106. </template>
  107. </el-table-column>
  108. </el-table>
  109. <div style="margin-top: 20px">
  110. <el-button @click="toggleSelection([tableData[1], tableData[2]])">切换第二、第三行的选中状态</el-button>
  111. <el-button @click="toggleSelection()">取消选择</el-button>
  112. </div>
  113. </el-row>
  114. <el-row>
  115. <el-pagination
  116. background
  117. :small="screenWidth <= 768"
  118. layout="prev, pager, next"
  119. :page-size="pageSize"
  120. :current-page="currentPage"
  121. :total="totalSize"
  122. @current-change="handleCurrentChange"
  123. @prev-click="handleCurrentChange"
  124. @next-click="handleCurrentChange"
  125. />
  126. </el-row>
  127. </el-row>
  128. </template>
  129. <script>
  130. import {cacheDataSource, deleteDataSource, getDataSource} from '@/api/admin'
  131. export default {
  132. name: 'DataSource',
  133. data() {
  134. return {
  135. // 屏幕宽度, 为了控制分页条的大小
  136. screenWidth: document.body.clientWidth,
  137. currentPage: 1,
  138. pageSize: 100,
  139. totalSize: 0,
  140. dataList: [],
  141. searchForm: {
  142. page: 1,
  143. status: '1',
  144. title: null
  145. },
  146. multipleSelection: []
  147. }
  148. },
  149. created() {
  150. document.title = '数据源'
  151. this.getData()
  152. },
  153. methods: {
  154. handleCurrentChange(pageNumber) {
  155. this.currentPage = pageNumber
  156. this.searchForm.page = this.currentPage
  157. this.getData()
  158. // 回到顶部
  159. scrollTo(0, 0)
  160. },
  161. getData() {
  162. this.dataList = []
  163. getDataSource(this.searchForm).then(resp => {
  164. if (resp.code === 0) {
  165. this.dataList = resp.data.list
  166. this.totalSize = resp.data.totalSize
  167. } else {
  168. this.$notify({
  169. title: '提示',
  170. message: resp.msg,
  171. type: 'warning',
  172. duration: 3000
  173. })
  174. }
  175. }).catch(error => {
  176. this.$notify({
  177. title: '提示',
  178. message: error.message,
  179. type: 'error',
  180. duration: 3000
  181. })
  182. })
  183. },
  184. cache(row) {
  185. cacheDataSource(row.magnetId).then(resp => {
  186. if (resp.code === 0) {
  187. this.$notify({
  188. message: row.title + ' 正在缓存中',
  189. type: 'warning',
  190. duration: 3000
  191. })
  192. } else {
  193. this.$notify({
  194. title: '提示',
  195. message: resp.msg,
  196. type: 'warning',
  197. duration: 3000
  198. })
  199. }
  200. })
  201. },
  202. search() {
  203. this.currentPage = 1
  204. this.searchForm.page = this.currentPage
  205. this.getData(this.searchForm)
  206. },
  207. toggleSelection(rows) {
  208. if (rows) {
  209. rows.forEach(row => {
  210. this.$refs.multipleTable.toggleRowSelection(row)
  211. })
  212. } else {
  213. this.$refs.multipleTable.clearSelection()
  214. }
  215. },
  216. handleSelectionChange(val) {
  217. this.multipleSelection = val
  218. },
  219. deleteMultiple() {
  220. if (this.multipleSelection.length === 0) {
  221. this.$notify({
  222. message: '至少应选中一行',
  223. type: 'warning',
  224. duration: 3000
  225. })
  226. }
  227. var magnetIds = []
  228. for (const item of this.multipleSelection) {
  229. magnetIds.push(item.magnetId)
  230. }
  231. deleteDataSource(magnetIds).then(resp => {
  232. if (resp.code === 0) {
  233. this.$notify({
  234. message: resp.msg,
  235. type: 'warning',
  236. duration: 3000
  237. })
  238. } else {
  239. this.$notify({
  240. title: '提示',
  241. message: resp.msg,
  242. type: 'warning',
  243. duration: 3000
  244. })
  245. }
  246. }).catch(error => {
  247. this.$notify({
  248. title: '提示',
  249. message: error.message,
  250. type: 'error',
  251. duration: 3000
  252. })
  253. })
  254. console.log(ids)
  255. }
  256. }
  257. }
  258. </script>
  259. <style>
  260. </style>