index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索区域 -->
  4. <div class="filter-container">
  5. <div class="filter-control">
  6. <span>资料包标题:</span>
  7. <el-input v-model="listQuery.fileTitle" placeholder="资料包标题" @keyup.enter.native="getList" />
  8. </div>
  9. <div class="filter-control">
  10. <span>审核状态:</span>
  11. <el-select v-model="listQuery.auditStatus" placeholder="审核状态" clearable @change="getList">
  12. <el-option label="全部" value="" />
  13. <el-option label="待审核" :value="2" />
  14. <el-option label="审核通过" :value="1" />
  15. <el-option label="审核未通过" :value="0" />
  16. </el-select>
  17. </div>
  18. <div class="filter-control">
  19. <span>上线状态:</span>
  20. <el-select v-model="listQuery.status" placeholder="上线状态" clearable @change="getList">
  21. <el-option label="全部" value="" />
  22. <el-option label="已上线" :value="1" />
  23. <el-option label="待上线" :value="2" />
  24. <el-option label="未上线" :value="0" />
  25. </el-select>
  26. </div>
  27. <div class="filter-control">
  28. <permission-button type="primary" @click="getList">查询</permission-button>
  29. <permission-button type="primary" @click="handleShowDialog('add')">添加资料包</permission-button>
  30. </div>
  31. </div>
  32. <!-- 搜索区域END -->
  33. <!-- 表格区域 -->
  34. <el-table
  35. v-loading="listLoading"
  36. :data="list"
  37. style="width: 100%"
  38. border
  39. fit
  40. highlight-current-row
  41. cell-class-name="table-cell"
  42. header-row-class-name="tableHeader"
  43. >
  44. <el-table-column label="序号" :index="indexMethod" type="index" width="80" align="center" />
  45. <el-table-column label="资料包标题" prop="fileTitle" align="center" />
  46. <el-table-column label="审核状态" width="120px" align="center">
  47. <template slot-scope="{ row }">
  48. <el-tag v-if="row.auditStatus === 2" size="small" type="warning">待审核</el-tag>
  49. <el-tag v-if="row.auditStatus === 1" size="small" type="success">审核通过</el-tag>
  50. <!-- 未通过原因展示 -->
  51. <template v-if="row.auditStatus === 0">
  52. <!-- <span class="status danger">审核未通过&nbsp;</span> -->
  53. <el-popover placement="top-start" title="审核说明" width="400" trigger="hover" :content="row.invalidReason">
  54. <el-tag slot="reference" size="small" type="danger" class="reason">
  55. <span>审核未通过</span>
  56. <span class="el-icon-question status danger " />
  57. </el-tag>
  58. </el-popover>
  59. <!-- 未通过原因展示END -->
  60. </template>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="上线状态" width="160px" align="center">
  64. <template slot-scope="{ row }">
  65. <!-- 只有审核通过了才能操作上下线 auditStatus :审核状态 -->
  66. <template v-if="row.auditStatus === 1">
  67. <template v-if="row.status === 0">
  68. <span style="margin-right:10px;" class="status danger">已下线</span>
  69. <permission-button type="primary" size="mini" @click="handleChangeStatus(row)">上线</permission-button>
  70. </template>
  71. <template v-else>
  72. <span style="margin-right:10px;" class="status success ">已上线</span>
  73. <permission-button type="info" size="mini" plain @click="handleChangeStatus(row)">下线</permission-button>
  74. </template>
  75. </template>
  76. <template v-else>
  77. <!-- <el-tag type="warning">待上线</el-tag> -->
  78. <span style="margin-right:10px;" class="status warning">待上线</span>
  79. </template>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="创建时间" width="160px" align="center">
  83. <template slot-scope="{ row }">
  84. {{ row.createTime | formatTime }}
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作" width="180px" align="center">
  88. <template slot-scope="{ row }">
  89. <permission-button
  90. type="primary"
  91. size="mini"
  92. style="margin-right:12px"
  93. @click="handleShowDialog('edit', row)"
  94. >编辑</permission-button>
  95. <permission-button
  96. type="danger"
  97. size="mini"
  98. style="margin-right:12px"
  99. @click="handleRemoveFile(row)"
  100. >删除</permission-button>
  101. </template>
  102. </el-table-column>
  103. </el-table>
  104. <!-- 表格区域END -->
  105. <pagination
  106. :total="total"
  107. :page.sync="listQuery.pageNum"
  108. :limit.sync="listQuery.pageSize"
  109. @pagination="getList(listQuery)"
  110. />
  111. <el-dialog
  112. :title="dialogTitle"
  113. :visible.sync="dialogVisible"
  114. width="40%"
  115. :close-on-click-modal="false"
  116. :close-on-press-escape="false"
  117. @close="beforeDialogClose"
  118. >
  119. <el-form ref="formRef" :model="dialogData" label-width="110px" :rules="dialogFormRules">
  120. <el-form-item label="资料包名称:" prop="fileTitle">
  121. <el-input v-model="dialogData.fileTitle" maxlength="50" show-word-limit />
  122. </el-form-item>
  123. <el-form-item label="资料包路径:" prop="fileName" style="margin-bottom:0">
  124. <upload-file
  125. ref="fileUpload"
  126. accept=".zip,.rar,.7z"
  127. mode="document"
  128. :file-list="fileList"
  129. :auto-upload="false"
  130. :before-upload="beforeUpload"
  131. @success="handleUploadFileSuccess"
  132. @remove="handleRemoveUploadFile"
  133. @change="handleChooseFileChange"
  134. />
  135. <el-input v-show="false" v-model="dialogData.fileName" />
  136. </el-form-item>
  137. </el-form>
  138. <div slot="footer" class="dialog-footer">
  139. <permission-button @click="dialogVisible = false">取 消</permission-button>
  140. <permission-button type="primary" :loading="submitLoading" @click="handleSave">提 交</permission-button>
  141. </div>
  142. </el-dialog>
  143. </div>
  144. </template>
  145. <script>
  146. import PermissionButton from '@/views/components/PermissionButton'
  147. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  148. import UploadFile from '@/components/UploadFile'
  149. import { mapGetters } from 'vuex'
  150. import { changeFileStatus, getFileList, removeFile, saveFile } from '@/api/doc'
  151. import openWindow from '@/utils/open-window'
  152. export default {
  153. components: { Pagination, UploadFile, PermissionButton },
  154. data() {
  155. return {
  156. listLoading: false, // 列表加载
  157. submitLoading: false, // 按钮加载
  158. total: 0, // 列表条数
  159. dialogVisible: false, // 是否显示dialog
  160. dialogTitle: '添加资料包:', // dialog标题
  161. listQuery: {
  162. fileType: 2,
  163. authUserId: '', // 供应商用户id
  164. listType: 1, // 列表类型:1文件列表,2文件审核列表
  165. fileTitle: '', // 文件标题
  166. auditStatus: '', // 审核状态:0审核未通过,1审核通过,2待审核
  167. status: '', // 文件状态:0已下线,1已上线,2待上线
  168. pageNum: 1, // 页码
  169. pageSize: 10 // 分页大小
  170. },
  171. fileList: [],
  172. // dialog表单中的数据
  173. dialogData: {
  174. fileType: 2,
  175. fileId: '',
  176. fileTitle: '',
  177. fileName: ''
  178. },
  179. // dialog表单数据校验规则
  180. dialogFormRules: {
  181. fileTitle: [{ required: true, message: '标题不能为空', trigger: 'blur' }],
  182. fileName: [{ required: true, message: '文件不能为空', trigger: 'change' }]
  183. },
  184. currentFileData: {
  185. filePreviewUrl: '',
  186. fileDownloadUrl: ''
  187. },
  188. list: []
  189. }
  190. },
  191. computed: {
  192. ...mapGetters(['authUserId', 'userIdentity'])
  193. },
  194. created() {
  195. this.getList()
  196. },
  197. methods: {
  198. // 小窗口浏览pdf文件
  199. handlePreviewFile(row) {
  200. openWindow(row.filePreviewUrl, row.fileTitle, row.fileTitle, 1200, 600)
  201. },
  202. // 获取列表数据
  203. getList() {
  204. this.listLoading = true
  205. this.listQuery.authUserId = this.authUserId
  206. getFileList(this.listQuery)
  207. .then(res => {
  208. if (res.code !== 0) return
  209. this.list = res.data.list
  210. this.total = res.data.total
  211. console.log(res)
  212. })
  213. .finally(() => {
  214. this.listLoading = false
  215. })
  216. },
  217. // 点击保存按钮
  218. handleSave() {
  219. const status = this.fileList.length > 0 && this.fileList[0].status
  220. if (status === 'success') {
  221. this.save()
  222. }
  223. if (status === 'ready') {
  224. this.submitLoading = true
  225. this.$refs.fileUpload.$refs.fileUpload.submit()
  226. }
  227. },
  228. // 调用保存数据接口
  229. save() {
  230. this.$refs.formRef.validate(valide => {
  231. if (!valide) return
  232. // 请求参数
  233. const params = {
  234. ...this.dialogData,
  235. ...this.currentFileData,
  236. authUserId: this.authUserId
  237. }
  238. saveFile(params)
  239. .then(res => {
  240. this.dialogVisible = false
  241. this.getList()
  242. this.$message({
  243. type: 'success',
  244. message: res.data,
  245. duration: 500
  246. })
  247. })
  248. .finally(() => {
  249. this.submitLoading = false
  250. })
  251. })
  252. },
  253. // 删除文件
  254. async handleRemoveFile(row) {
  255. const text = await this.$confirm('文件删除后不可恢复,确认删除该文件吗?', '提示', {
  256. confirmButtonText: '确定',
  257. cancelButtonText: '取消',
  258. type: 'warning'
  259. }).catch(() => {
  260. this.$message.info('已取消操作')
  261. })
  262. if (text !== 'confirm') return
  263. removeFile({ fileId: row.fileId }).then(res => {
  264. if (res.code !== 0) return
  265. this.$message.success(res.data)
  266. this.getList()
  267. })
  268. },
  269. // 状态改变
  270. handleChangeStatus(item) {
  271. this.listLoading = true
  272. const params = {
  273. fileId: item.fileId,
  274. status: item.status === 1 ? 0 : 1
  275. }
  276. changeFileStatus(params)
  277. .then(res => {
  278. this.$message({
  279. message: res.data,
  280. duration: 500,
  281. type: 'success'
  282. })
  283. this.getList()
  284. })
  285. .finally(() => {
  286. this.listLoading = false
  287. })
  288. },
  289. // 显示dialog对话框
  290. handleShowDialog(type, row) {
  291. this.dialogTitle = '添加资料包'
  292. if (type === 'edit') {
  293. this.dialogTitle = '修改资料包'
  294. this.setDialogData(row)
  295. }
  296. this.dialogVisible = true
  297. },
  298. // 设置表单初始值
  299. setDialogData(row) {
  300. if (typeof row !== 'object') return
  301. setTimeout(() => {
  302. for (const key in this.dialogData) {
  303. if (Object.hasOwnProperty.call(this.dialogData, key)) {
  304. this.dialogData[key] = row[key]
  305. }
  306. }
  307. this.resetCurrentFileData(row)
  308. if (row.filePreviewUrl && row.fileDownloadUrl && row.fileId) {
  309. this.fileList = [{ name: row.fileName }]
  310. }
  311. }, 100)
  312. },
  313. // 对话框关闭前的回调
  314. beforeDialogClose() {
  315. this.$refs.formRef.resetFields()
  316. this.$refs.fileUpload.$refs.fileUpload.abort()
  317. this.fileList = []
  318. this.dialogData.fileId = ''
  319. this.submitLoading = false
  320. this.resetCurrentFileData()
  321. },
  322. // 上传文件成功
  323. handleUploadFileSuccess({ response, file, fileList }) {
  324. console.log(response)
  325. this.fileList = fileList
  326. this.dialogData.fileName = response.fileName
  327. this.currentFileData.filePreviewUrl = response.previewUrl
  328. this.currentFileData.fileDownloadUrl = response.downloadUrl
  329. this.save()
  330. },
  331. // 移除文件
  332. handleRemoveUploadFile({ response, file, fileList }) {
  333. this.fileList = []
  334. this.dialogData.fileName = ''
  335. this.resetCurrentFileData()
  336. },
  337. // 文件选择
  338. handleChooseFileChange({ file, fileList }) {
  339. this.fileList = fileList
  340. this.dialogData.fileName = file.name
  341. this.resetCurrentFileData()
  342. },
  343. // 重置选中文件数据
  344. resetCurrentFileData(row = {}) {
  345. this.currentFileData.filePreviewUrl = row.filePreviewUrl || ''
  346. this.currentFileData.fileDownloadUrl = row.fileDownloadUrl || ''
  347. },
  348. // 文件上传之前
  349. beforeUpload(file, fileList) {
  350. let maxSize = 500
  351. // 文件过大
  352. if (file.size > maxSize * 1024 * 1024) {
  353. this.$message.warning('文件大小超过500MB,请重新选择!')
  354. return Promise.reject()
  355. }
  356. maxSize = 30
  357. // 直接上传
  358. if (file.size <= maxSize * 1024 * 1024) return true
  359. // 用户确认上传
  360. return this.$confirm(`您上传的文件大于${maxSize}MB,是否继续上传?文件上传过程中请您耐心等待!`, '文件上传提示', {
  361. confirmButtonText: '继续',
  362. cancelButtonText: '取消',
  363. type: 'warning'
  364. })
  365. .then(() => {
  366. return Promise.resolve()
  367. })
  368. .catch(() => {
  369. this.$message.info('已取消上传')
  370. this.submitLoading = false
  371. return Promise.reject()
  372. })
  373. },
  374. // 表格索引
  375. indexMethod(index) {
  376. return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
  377. }
  378. }
  379. }
  380. </script>
  381. <style lang="scss" scoped>
  382. .el-table .cell {
  383. overflow: visible;
  384. }
  385. .el-badge {
  386. margin: 0 6px;
  387. }
  388. </style>