|
@@ -145,40 +145,31 @@
|
|
|
:limit.sync="listQuery.pageSize"
|
|
|
@pagination="getList(listQuery)"
|
|
|
/>
|
|
|
- <!-- 视频预览对话框 -->
|
|
|
<el-dialog
|
|
|
:title="dialogTitle"
|
|
|
:visible.sync="dialogVisible"
|
|
|
width="40%"
|
|
|
:close-on-click-modal="false"
|
|
|
:close-on-press-escape="false"
|
|
|
- @closed="dialogColosed"
|
|
|
@close="beforeDialogClose"
|
|
|
>
|
|
|
<el-form ref="formRef" :model="dialogData" label-width="110px" :rules="dialogFormRules">
|
|
|
<el-form-item label="标题:" prop="fileTitle">
|
|
|
<el-input v-model="dialogData.fileTitle" maxlength="50" show-word-limit />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="上传文件:" prop="filePreviewUrl" style="margin-bottom:0">
|
|
|
- <div class="file-upload-box">
|
|
|
- <!-- 上传文件组件 -->
|
|
|
- <el-upload
|
|
|
- ref="uploadFileRef"
|
|
|
- accept=".pdf"
|
|
|
- :class="{ hidden: hasFile }"
|
|
|
- :auto-upload="false"
|
|
|
- :headers="headers"
|
|
|
- :action="action"
|
|
|
- :on-success="fileUploadSuccess"
|
|
|
- :on-change="fileUploadChange"
|
|
|
- :on-remove="fileUploadRemove"
|
|
|
- :before-upload="beforeUpload"
|
|
|
- :file-list="fileList"
|
|
|
- >
|
|
|
- <el-button size="mini" type="primary" style="width:100%">上传文件</el-button>
|
|
|
- </el-upload>
|
|
|
- <el-input v-model="dialogData.filePreviewUrl" type="hidden" class="hiddenInput" />
|
|
|
- </div>
|
|
|
+ <el-form-item label="上传文件:" prop="fileName" style="margin-bottom:0">
|
|
|
+ <upload-file
|
|
|
+ ref="fileUpload"
|
|
|
+ accept=".pdf"
|
|
|
+ mode="document"
|
|
|
+ :file-list="fileList"
|
|
|
+ :auto-upload="false"
|
|
|
+ :before-upload="beforeUpload"
|
|
|
+ @success="handleUploadFileSuccess"
|
|
|
+ @remove="handleRemoveUploadFile"
|
|
|
+ @change="handleChooseFileChange"
|
|
|
+ />
|
|
|
+ <el-input v-show="false" v-model="dialogData.fileName" />
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
<div slot="footer" class="dialog-footer">
|
|
@@ -186,19 +177,18 @@
|
|
|
<el-button type="primary" :loading="submitLoading" @click="handleSave">提 交</el-button>
|
|
|
</div>
|
|
|
</el-dialog>
|
|
|
- <!-- 视频预览对话框END -->
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
|
|
|
+import UploadFile from '@/components/UploadFile'
|
|
|
import { formatDate } from '@/utils'
|
|
|
import { mapGetters } from 'vuex'
|
|
|
-import { getToken } from '@/utils/auth'
|
|
|
import { changeFileStatus, getFileList, removeFile, saveFile } from '@/api/doc'
|
|
|
import openWindow from '@/utils/open-window'
|
|
|
export default {
|
|
|
- components: { Pagination },
|
|
|
+ components: { Pagination, UploadFile },
|
|
|
filters: {
|
|
|
formatTime(time) {
|
|
|
if (!time) {
|
|
@@ -214,57 +204,43 @@ export default {
|
|
|
total: 0, // 列表条数
|
|
|
dialogVisible: false, // 是否显示dialog
|
|
|
dialogTitle: '添加文件', // dialog标题
|
|
|
- hasFile: false, // 是否上传了文件
|
|
|
- previewUrl: '', // 上传文件成功后的url
|
|
|
- downloadUrl: '',
|
|
|
- chooseNewFile: false, // 是否选择了新的图片上传
|
|
|
listQuery: {
|
|
|
authUserId: '', // 供应商用户id
|
|
|
- listType: 1, // 列表类型:1视频列表,2视频审核列表
|
|
|
+ listType: 1, // 列表类型:1文件列表,2文件审核列表
|
|
|
fileTitle: '', // 文件标题
|
|
|
auditStatus: '', // 审核状态:0审核未通过,1审核通过,2待审核
|
|
|
- status: '', // 视频状态:0已下线,1已上线,2待上线
|
|
|
+ status: '', // 文件状态:0已下线,1已上线,2待上线
|
|
|
pageNum: 1, // 页码
|
|
|
pageSize: 10 // 分页大小
|
|
|
},
|
|
|
fileList: [],
|
|
|
// dialog表单中的数据
|
|
|
dialogData: {
|
|
|
- authUserId: '',
|
|
|
- fileTitle: '',
|
|
|
fileId: '',
|
|
|
- // fileUrl: '',
|
|
|
- fileName: '',
|
|
|
- filePreviewUrl: '',
|
|
|
- fileDownloadUrl: ''
|
|
|
+ fileTitle: '',
|
|
|
+ fileName: ''
|
|
|
},
|
|
|
// dialog表单数据校验规则
|
|
|
dialogFormRules: {
|
|
|
fileTitle: [{ required: true, message: '标题不能为空', trigger: 'blur' }],
|
|
|
- filePreviewUrl: [{ required: true, message: '文件不能为空', trigger: 'change' }]
|
|
|
+ fileName: [{ required: true, message: '文件不能为空', trigger: 'change' }]
|
|
|
+ },
|
|
|
+ currentFileData: {
|
|
|
+ filePreviewUrl: '',
|
|
|
+ fileDownloadUrl: ''
|
|
|
},
|
|
|
list: []
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- ...mapGetters(['authUserId', 'userIdentity', 'proxyInfo']),
|
|
|
- headers() {
|
|
|
- return {
|
|
|
- 'X-Token': getToken()
|
|
|
- }
|
|
|
- },
|
|
|
- action() {
|
|
|
- return `${process.env.VUE_APP_UPLOAD_API}/upload/file`
|
|
|
- }
|
|
|
+ ...mapGetters(['authUserId', 'userIdentity', 'proxyInfo'])
|
|
|
},
|
|
|
created() {
|
|
|
this.getList()
|
|
|
},
|
|
|
methods: {
|
|
|
-
|
|
|
// 小窗口浏览pdf文件
|
|
|
handlePreviewFile(row) {
|
|
|
- console.log(row)
|
|
|
openWindow(row.filePreviewUrl, row.fileTitle, row.fileTitle, 1200, 600)
|
|
|
},
|
|
|
|
|
@@ -283,37 +259,32 @@ export default {
|
|
|
this.listLoading = false
|
|
|
})
|
|
|
},
|
|
|
+
|
|
|
// 点击保存按钮
|
|
|
handleSave() {
|
|
|
- if (!this.dialogData.fileTitle || !this.dialogData.filePreviewUrl) {
|
|
|
- this.$refs.formRef.validateField('fileTitle')
|
|
|
- this.$refs.formRef.validateField('filePreviewUrl')
|
|
|
- return
|
|
|
+ const status = this.fileList.length > 0 && this.fileList[0].status
|
|
|
+ if (status === 'success') {
|
|
|
+ this.save()
|
|
|
+ }
|
|
|
+ if (status === 'ready') {
|
|
|
+ this.submitLoading = true
|
|
|
+ this.$refs.fileUpload.$refs.fileUpload.submit()
|
|
|
}
|
|
|
- // 对标题字段进行规则校验
|
|
|
- console.log(this.dialogData)
|
|
|
- this.$refs.formRef.validateField('fileTitle', error => {
|
|
|
- if (!error) {
|
|
|
- this.submitLoading = true
|
|
|
- this.hasFile && !this.chooseNewFile ? this.save() : this.$refs.uploadFileRef.submit()
|
|
|
- }
|
|
|
- })
|
|
|
},
|
|
|
+
|
|
|
// 调用保存数据接口
|
|
|
save() {
|
|
|
this.$refs.formRef.validate(valide => {
|
|
|
if (!valide) return
|
|
|
- this.dialogData.authUserId = this.authUserId
|
|
|
- if (this.previewUrl && this.downloadUrl) {
|
|
|
- this.dialogData.filePreviewUrl = this.previewUrl
|
|
|
- this.dialogData.fileDownloadUrl = this.downloadUrl
|
|
|
+ // 请求参数
|
|
|
+ const params = {
|
|
|
+ ...this.dialogData,
|
|
|
+ ...this.currentFileData,
|
|
|
+ authUserId: this.authUserId
|
|
|
}
|
|
|
- console.log(this.dialogData)
|
|
|
- console.log('保存')
|
|
|
- saveFile(this.dialogData)
|
|
|
+
|
|
|
+ saveFile(params)
|
|
|
.then(res => {
|
|
|
- console.log(res)
|
|
|
- if (res.code !== 0) return
|
|
|
this.dialogVisible = false
|
|
|
this.getList()
|
|
|
this.$message({
|
|
@@ -327,9 +298,10 @@ export default {
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
- // 删除视频
|
|
|
+
|
|
|
+ // 删除文件
|
|
|
async handleRemoveFile(row) {
|
|
|
- const text = await this.$confirm('视频删除后不可恢复,确认删除该视频吗?', '提示', {
|
|
|
+ const text = await this.$confirm('文件删除后不可恢复,确认删除该文件吗?', '提示', {
|
|
|
confirmButtonText: '确定',
|
|
|
cancelButtonText: '取消',
|
|
|
type: 'warning'
|
|
@@ -343,116 +315,121 @@ export default {
|
|
|
this.getList()
|
|
|
})
|
|
|
},
|
|
|
+
|
|
|
+ // 状态改变
|
|
|
+ handleChangeStatus(item) {
|
|
|
+ this.listLoading = true
|
|
|
+ const params = {
|
|
|
+ fileId: item.fileId,
|
|
|
+ status: item.status === 1 ? 0 : 1
|
|
|
+ }
|
|
|
+ changeFileStatus(params)
|
|
|
+ .then(res => {
|
|
|
+ this.$message({
|
|
|
+ message: res.data,
|
|
|
+ duration: 500,
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ this.getList()
|
|
|
+ }).finally(() => {
|
|
|
+ this.listLoading = false
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
// 显示dialog对话框
|
|
|
handleShowDialog(type, row) {
|
|
|
- this.dialogTitle = type === 'add' ? '添加文件' : '修改文件'
|
|
|
- this.$refs?.formRef?.resetFields()
|
|
|
- this.dialogVisible = true
|
|
|
- if (type !== 'add') {
|
|
|
+ this.dialogTitle = '添加文件'
|
|
|
+ if (type === 'edit') {
|
|
|
+ this.dialogTitle = '修改文件'
|
|
|
this.setDialogData(row)
|
|
|
}
|
|
|
+ this.dialogVisible = true
|
|
|
},
|
|
|
+
|
|
|
// 设置表单初始值
|
|
|
setDialogData(row) {
|
|
|
- console.log(row)
|
|
|
- if (!row) return
|
|
|
- for (const key in this.dialogData) {
|
|
|
- if (Object.hasOwnProperty.call(this.dialogData, key)) {
|
|
|
- this.dialogData[key] = row[key]
|
|
|
+ if (typeof row !== 'object') return
|
|
|
+ setTimeout(() => {
|
|
|
+ for (const key in this.dialogData) {
|
|
|
+ if (Object.hasOwnProperty.call(this.dialogData, key)) {
|
|
|
+ this.dialogData[key] = row[key]
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if (this.dialogData.filePreviewUrl) {
|
|
|
- this.fileList = [{ name: row.fileName, url: row.filePreviewUrl }]
|
|
|
- this.hasFile = true
|
|
|
- }
|
|
|
- },
|
|
|
- // dialog对话框关闭时的回调
|
|
|
- dialogColosed() {
|
|
|
- this.dialogData.authUserId = ''
|
|
|
- this.dialogData.fileTitle = ''
|
|
|
- this.dialogData.fileId = ''
|
|
|
- this.dialogData.filePreviewUrl = ''
|
|
|
- this.dialogData.fileDownloadUrl = ''
|
|
|
- this.dialogData.fileName = ''
|
|
|
- this.previewUrl = ''
|
|
|
- this.downloadUrl = ''
|
|
|
- this.chooseNewFile = false
|
|
|
- this.hasFile = false
|
|
|
- this.fileList = []
|
|
|
- this.submitLoading = false
|
|
|
- console.log(this.dialogData)
|
|
|
+
|
|
|
+ this.resetCurrentFileData(row)
|
|
|
+
|
|
|
+ if (row.filePreviewUrl && row.fileDownloadUrl && row.fileId) {
|
|
|
+ this.fileList = [{ name: row.fileName }]
|
|
|
+ }
|
|
|
+ }, 100)
|
|
|
},
|
|
|
+
|
|
|
// 对话框关闭前的回调
|
|
|
beforeDialogClose() {
|
|
|
- console.log('对话框关闭')
|
|
|
- // this.$refs.formRef.clearValidate()
|
|
|
- // 停止上传文件
|
|
|
this.$refs.formRef.resetFields()
|
|
|
- this.$refs.uploadFileRef.abort()
|
|
|
+ this.$refs.fileUpload.$refs.fileUpload.abort()
|
|
|
+ this.fileList = []
|
|
|
+ this.dialogData.fileId = ''
|
|
|
+ this.submitLoading = false
|
|
|
+ this.resetCurrentFileData()
|
|
|
},
|
|
|
+
|
|
|
// 上传文件成功
|
|
|
- fileUploadSuccess(response) {
|
|
|
- // this.dialogData.fileUrl = response.fileUrl
|
|
|
- this.previewUrl = response.previewUrl
|
|
|
- this.downloadUrl = response.downloadUrl
|
|
|
+ handleUploadFileSuccess({ response, file, fileList }) {
|
|
|
+ console.log(response)
|
|
|
+ this.fileList = fileList
|
|
|
this.dialogData.fileName = response.fileName
|
|
|
+ this.currentFileData.filePreviewUrl = response.previewUrl
|
|
|
+ this.currentFileData.fileDownloadUrl = response.downloadUrl
|
|
|
this.save()
|
|
|
- console.log(response)
|
|
|
- },
|
|
|
- // 上传文件成功,选择文件,上传文件失败的回调
|
|
|
- fileUploadChange(file, fileList) {
|
|
|
- this.hasFile = fileList.length > 0
|
|
|
- this.dialogData.filePreviewUrl = '-'
|
|
|
- this.dialogData.fileDownloadUrl = '-'
|
|
|
- this.chooseNewFile = true
|
|
|
},
|
|
|
+
|
|
|
// 移除文件
|
|
|
- fileUploadRemove(file, fileList) {
|
|
|
- this.dialogData.filePreviewUrl = ''
|
|
|
- this.dialogData.fileDownloadUrl = ''
|
|
|
- this.hasFile = fileList.length > 0
|
|
|
+ handleRemoveUploadFile({ response, file, fileList }) {
|
|
|
+ this.fileList = []
|
|
|
+ this.dialogData.fileName = ''
|
|
|
+ this.resetCurrentFileData()
|
|
|
},
|
|
|
- beforeUpload(file, fileList) {
|
|
|
- const flag = file.size <= 100 * 1024 * 1204
|
|
|
- if (!flag) {
|
|
|
- this.$message({
|
|
|
- message: '文件大小超过100MB,请重新选择!',
|
|
|
- duration: 1000,
|
|
|
- type: 'warning'
|
|
|
- })
|
|
|
- this.fileList = []
|
|
|
- }
|
|
|
- return flag
|
|
|
+
|
|
|
+ // 文件选择
|
|
|
+ handleChooseFileChange({ file, fileList }) {
|
|
|
+ this.fileList = fileList
|
|
|
+ this.dialogData.fileName = file.name
|
|
|
+ this.resetCurrentFileData()
|
|
|
},
|
|
|
- // 状态改变
|
|
|
- handleChangeStatus(item) {
|
|
|
- this.listLoading = true
|
|
|
- // const params = {
|
|
|
- // authId: item.authId,
|
|
|
- // status: item.status ? 1 : 0
|
|
|
- // }
|
|
|
- console.log(item)
|
|
|
- const params = {
|
|
|
- fileId: item.fileId,
|
|
|
- status: item.status === 1 ? 0 : 1
|
|
|
+
|
|
|
+ // 重置选中文件数据
|
|
|
+ resetCurrentFileData(row = {}) {
|
|
|
+ this.currentFileData.filePreviewUrl = row.filePreviewUrl || ''
|
|
|
+ this.currentFileData.fileDownloadUrl = row.fileDownloadUrl || ''
|
|
|
+ },
|
|
|
+
|
|
|
+ // 文件上传之前
|
|
|
+ beforeUpload(file, fileList) {
|
|
|
+ let maxSize = 100
|
|
|
+ // 文件过大
|
|
|
+ if (file.size > maxSize * 1024 * 1024) {
|
|
|
+ this.$message.warning('文件大小超过100MB,请重新选择!')
|
|
|
+ return Promise.reject()
|
|
|
}
|
|
|
- changeFileStatus(params)
|
|
|
- .then(res => {
|
|
|
- // this.$message.success(res.data)
|
|
|
- this.$message({
|
|
|
- message: res.data,
|
|
|
- duration: 500,
|
|
|
- type: 'success'
|
|
|
- })
|
|
|
- this.getList()
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err)
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
- this.listLoading = false
|
|
|
- })
|
|
|
+ maxSize = 30
|
|
|
+ // 直接上传
|
|
|
+ if (file.size <= maxSize * 1024 * 1024) return true
|
|
|
+ // 用户确认上传
|
|
|
+ return this.$confirm(`您上传的文件大于${maxSize}MB,是否继续上传?文件上传过程中请您耐心等待!`, '文件上传提示', {
|
|
|
+ confirmButtonText: '继续',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ return Promise.resolve()
|
|
|
+ }).catch(() => {
|
|
|
+ this.$message.info('已取消上传')
|
|
|
+ this.submitLoading = false
|
|
|
+ return Promise.reject()
|
|
|
+ })
|
|
|
},
|
|
|
+
|
|
|
+ // 表格索引
|
|
|
indexMethod(index) {
|
|
|
return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
|
|
|
}
|