index.vue 13 KB

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