index.vue 15 KB

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