提交 8e501b21 authored 作者: 龙菲's avatar 龙菲

完善抠图详情内的逻辑

上级 fcaeffdb
...@@ -49,7 +49,7 @@ export function deleteMattingImage(data) { ...@@ -49,7 +49,7 @@ export function deleteMattingImage(data) {
export function getMattingImagesPage(data) { export function getMattingImagesPage(data) {
return request({ return request({
url: '/bizMattingImages/listByPage', url: '/bizMattingImages/listByPage',
method: 'delete', method: 'post',
data data
}) })
} }
...@@ -69,7 +69,8 @@ export function downFileByFileIds(data) { ...@@ -69,7 +69,8 @@ export function downFileByFileIds(data) {
return request({ return request({
url: '/bizMattingImages/downLoad', url: '/bizMattingImages/downLoad',
method: 'post', method: 'post',
data data,
responseType: 'blob',
}) })
} }
......
<template> <template>
<span> <span>
<el-button v-bind="$attrs" v-on="$listeners" v-if="hasPer && button"> <el-button
style="width: 100%"
v-bind="$attrs"
v-on="$listeners"
v-if="hasPer && button"
>
<slot /> <slot />
</el-button> </el-button>
<el-link v-bind="$attrs" v-on="$listeners" v-else-if="hasPer"> <el-link v-bind="$attrs" v-on="$listeners" v-else-if="hasPer">
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
<slot name="expand" :scope="scope.$index"></slot> <slot name="expand" :scope="scope.$index"></slot>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column v-if="hasMultiSelection" type="selection" width="55" />
<el-table-column type="index" width="50" label="序号" align="center"> <el-table-column type="index" width="50" label="序号" align="center">
</el-table-column> </el-table-column>
<el-table-column v-if="hasMultiSelection" type="selection" width="55" />
<el-table-column <el-table-column
v-for="(item, index) in tableTitle" v-for="(item, index) in tableTitle"
:key="index" :key="index"
......
...@@ -34,9 +34,8 @@ ...@@ -34,9 +34,8 @@
ref="upload" ref="upload"
class="upload-area" class="upload-area"
name="zipFile" name="zipFile"
action="#"
:accept="fileType" :accept="fileType"
:action="uploadUrl"
:headers="headers"
:on-success="handleSuccess" :on-success="handleSuccess"
:on-change="handleChange" :on-change="handleChange"
:auto-upload="false" :auto-upload="false"
...@@ -134,12 +133,6 @@ export default { ...@@ -134,12 +133,6 @@ export default {
return (size / 1024 / 1024).toFixed(2) + "M"; //1M=1024Kb=1024*1024byte return (size / 1024 / 1024).toFixed(2) + "M"; //1M=1024Kb=1024*1024byte
}; };
}, },
uploadUrl() {
if (!this.options) {
return;
}
return this.options.uploadUrl;
},
fileType() { fileType() {
if (!this.options) { if (!this.options) {
return; return;
...@@ -251,8 +244,19 @@ export default { ...@@ -251,8 +244,19 @@ export default {
formData.append(titleKey, uploadTitle); formData.append(titleKey, uploadTitle);
return formData; return formData;
}, },
// 判断文件是否符合规则校验
getFileValid(file) {
const { name } = file;
const suffix = name.split(".")[1].toLowerCase();
return suffix && this.fileType.includes(suffix);
},
// 上传函数实现逻辑 // 上传函数实现逻辑
uploadSelf(file, index) { uploadSelf(file, index) {
const isValid = this.getFileValid(file);
if (!isValid) {
this.$message.error(`文件格式错误:请上传${this.fileType}格式的文件!`);
return;
}
const loading = this.$loading({ const loading = this.$loading({
lock: true, lock: true,
text: "正在上传中...文件较大,请耐心等待,请勿刷新页面", text: "正在上传中...文件较大,请耐心等待,请勿刷新页面",
...@@ -261,6 +265,7 @@ export default { ...@@ -261,6 +265,7 @@ export default {
}); });
const formData = this.getFormData(file); const formData = this.getFormData(file);
importZip( importZip(
this.options.uploadUrl,
formData, formData,
(progressEvent) => this.uploadUnderWayCallback(progressEvent, index), (progressEvent) => this.uploadUnderWayCallback(progressEvent, index),
(cancelCallback) => this.cancelCallBack(cancelCallback, index) (cancelCallback) => this.cancelCallBack(cancelCallback, index)
......
...@@ -2,6 +2,7 @@ import axios from 'axios' ...@@ -2,6 +2,7 @@ import axios from 'axios'
import { import {
getToken getToken
} from '@/utils/auth' } from '@/utils/auth'
import { Message } from 'element-ui'
var uploadUrl = process.env.VUE_APP_BASE_API + "/sysFiles/upload" var uploadUrl = process.env.VUE_APP_BASE_API + "/sysFiles/upload"
var uploadV1Url = process.env.VUE_APP_BASE_API + "/sysFiles/v1/upload" var uploadV1Url = process.env.VUE_APP_BASE_API + "/sysFiles/v1/upload"
...@@ -49,13 +50,14 @@ export function uploadV1(data) { ...@@ -49,13 +50,14 @@ export function uploadV1(data) {
/** /**
* 批量上传文件 * 批量上传文件
* @param data formData类型 * 参数1 type:导入数据类别(biz_cultural_relic、biz_exhibition二选一) 参数2 zipFile:zip压缩文件 * @param {String} importZipUrl 上传地址
* @param callback 用于获取上传进度 * @param {FormData} data * 参数1 type:导入数据类别(biz_cultural_relic、biz_exhibition二选一) 参数2 zipFile:zip压缩文件
* @param cancelCallBack 用于取消上传 * @param {Function} callback 用于获取上传进度
* @param {Function} cancelCallBack 用于取消上传
* @returns {Promise} * @returns {Promise}
*/ */
let CancelToken = axios.CancelToken; let CancelToken = axios.CancelToken;
export function importZip(data, callback, cancelCallBack) { export function importZip(importZipUrl, data, callback, cancelCallBack) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.post(importZipUrl, data, { axios.post(importZipUrl, data, {
headers: { headers: {
...@@ -111,41 +113,61 @@ export function previewFile(href, previewName) { ...@@ -111,41 +113,61 @@ export function previewFile(href, previewName) {
} }
/**
* 处理返回的二进制流并触发为下载文件
* @param {*} response 下载返回的二进制流
* @param {*} fileName 希望展示的文件名称
* @param {*} suffix 希望下载展示的文件后缀
*/
export function triggrtUrl(response, fileName, suffix) {
const blob = new Blob([response.data])
const link = document.createElement('a')
link.href = URL.createObjectURL(blob)
if (suffix) {
link.download = fileName + '.' + suffix
} else {
link.download = fileName
}
link.click()
URL.revokeObjectURL(link.href)
}
/** /**
* 下载文件 * 下载文件
* @param url 下载地址 * @param url 下载地址
* @param fileName 下载文件用户看到的名称 * @param fileName 下载文件用户看到的名称
* @param typeSuffix 文件后缀 * @param typeSuffix 文件后缀
*/ */
export function downloadBlob(url, fileName, typeSuffix) { export function downloadBlob({ url, method = 'get', fileName, suffix, data }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios({ const startMsg = Message.warning('正在下载...')
const options = {
url, url,
method: 'get', method,
responseType: 'blob', responseType: 'blob',
headers: { headers: {
'authorization': getToken() 'authorization': getToken()
} }
}). }
if (data) {
options.data = data
}
axios(options).
then(response => { then(response => {
const blob = new Blob([response.data]) startMsg.close()
const link = document.createElement('a') Message.success('下载成功!')
link.href = URL.createObjectURL(blob) triggrtUrl(response, fileName, suffix)
if (typeSuffix) { resolve(response)
link.download = fileName + '.' + typeSuffix
} else {
link.download = fileName
}
link.click()
URL.revokeObjectURL(link.href)
resolve()
}).catch(err => { }).catch(err => {
startMsg.close()
console.error(err); console.error(err);
Message.error('下载失败:' + err)
reject(err) reject(err)
}) })
}) })
}; };
// 因为之前的全部都是单独引入,为了不改变以前的代码因此单独用file导出,后期方便$file.uploadFile进行使用 // 因为之前的全部都是单独引入,为了不改变以前的代码因此单独用file导出,后期方便$file.uploadFile进行使用
export const file = { export const file = {
uploadFile, uploadFile,
...@@ -153,5 +175,6 @@ export const file = { ...@@ -153,5 +175,6 @@ export const file = {
importZip, importZip,
downloadFile, downloadFile,
previewFile, previewFile,
downloadBlob downloadBlob,
triggrtUrl
} }
\ No newline at end of file
...@@ -175,19 +175,6 @@ export const Throttle = (fn, t) => { ...@@ -175,19 +175,6 @@ export const Throttle = (fn, t) => {
} }
} }
// // 获取完整的url,根据环境进行配置
// export function getFullUrl(url) {
// let fullUrl = ''
// if (url && url.indexOf('http') != -1 && url.indexOf('files') != -1) {
// let urlArr = url.split('files')
// fullUrl = '/files' + urlArr[1]
// } else if (url && url.indexOf('http') == -1 && url.indexOf('files') == -1) {
// fullUrl = '/files' + url
// } else {
// fullUrl = url
// }
// return fullUrl
// }
// 获取完整的url,根据环境进行配置 // 获取完整的url,根据环境进行配置
export function getFullUrl(url) { export function getFullUrl(url) {
......
...@@ -224,7 +224,16 @@ export default { ...@@ -224,7 +224,16 @@ export default {
let msg = this.$message.info("正在准备下载..."); let msg = this.$message.info("正在准备下载...");
let url = "/files" + files[0].url.split("files")[1]; let url = "/files" + files[0].url.split("files")[1];
const { name } = row; const { name } = row;
downloadBlob(url, name, "pdf") const method = "get";
const fileName = name;
const suffix = "pdf";
const options = {
url,
method,
fileName,
suffix,
};
downloadBlob(options)
.then((res) => { .then((res) => {
msg.close(); msg.close();
this.$message.success("下载成功!"); this.$message.success("下载成功!");
......
...@@ -29,18 +29,18 @@ export const tableTitle = [{ ...@@ -29,18 +29,18 @@ export const tableTitle = [{
label: "创建时间", label: "创建时间",
columnAlign: 'center', columnAlign: 'center',
}, },
{ // {
prop: "createName", // prop: "createName",
label: "创建人", // label: "创建人",
columnAlign: 'center', // columnAlign: 'center',
showOverFlowToolTip: true, // showOverFlowToolTip: true,
}, // },
{ // {
prop: "remark", // prop: "remark",
label: "备注", // label: "备注",
columnAlign: 'center', // columnAlign: 'center',
}, // },
] ]
...@@ -52,25 +52,21 @@ export const operates = { ...@@ -52,25 +52,21 @@ export const operates = {
width: "280px", width: "280px",
} }
export const operations = [ export const viewButton = {
{ type: 'view',
type: 'view', title: '查看详情',
title: '查看详情', perms: 'bizMattingImages:detail',
perms: 'bizCulturalRelic:list',//暂时使用展览的列表 }
}, export const downloadButton = {
type: 'download',
{ title: '下载',
type: 'download', perms: 'bizMattingImages:download',
title: '下载', }
perms: 'bizCulturalRelic:list',//暂时使用展览的列表 export const deleteButton = {
}, type: 'delete',
{ title: '删除',
type: 'delete', perms: 'bizMattingImages:delete',
title: '删除', }
perms: 'bizCulturalRelic:delete',//暂时使用展览的列表
},
]
// 搜索配置 // 搜索配置
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<el-dropdown @command="handleCommand"> <el-dropdown @command="handleCommand">
<PermissionButton <PermissionButton
button button
perms="bizCulturalRelic:add" perms="bizMattingImages:add"
type="primary" type="primary"
size="mini" size="mini"
icon="el-icon-upload2" icon="el-icon-upload2"
...@@ -24,12 +24,41 @@ ...@@ -24,12 +24,41 @@
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
</div> </div>
<div class="tools-item">
<PermissionButton
button
perms="bizMattingImages:download"
type="primary"
size="mini"
icon="el-icon-download"
style="margin-right: 10px"
:disabled="multiDisabled"
plain
@click="handleMultiDownload"
>
批量下载
</PermissionButton>
<PermissionButton
button
perms="bizMattingImages:delete"
type="danger"
plain
size="mini"
icon="el-icon-delete"
:disabled="multiDisabled"
@click="handleMultiDelete"
>
批量删除
</PermissionButton>
</div>
</div> </div>
<div class="list"> <div class="list">
<TablePage <TablePage
:data="list.records" :data="list.records"
:tableTitle="tableTitle" :tableTitle="tableTitle"
:operates="operates" :operates="operates"
hasMultiSelection
@handleSelectionChange="handleSelectionChange"
> >
<template v-slot:status="{ scope }"> <template v-slot:status="{ scope }">
<el-tag <el-tag
...@@ -42,7 +71,7 @@ ...@@ -42,7 +71,7 @@
</template> </template>
<template v-slot:operates="{ scope }"> <template v-slot:operates="{ scope }">
<TableOperation <TableOperation
:operations="operations" :operations="getOperations(scope.status)"
:rawData="scope" :rawData="scope"
@handleOperation="handleOperation" @handleOperation="handleOperation"
></TableOperation> ></TableOperation>
...@@ -65,7 +94,7 @@ ...@@ -65,7 +94,7 @@
@update="loadData" @update="loadData"
:options="uploadOptions" :options="uploadOptions"
/> />
<PreviewDialog ref="PreviewDialog" :detail="currentPreviewItem" /> <PreviewDialog ref="PreviewDialog" :detail="previewInfo" />
</div> </div>
<el-image-viewer <el-image-viewer
...@@ -77,11 +106,24 @@ ...@@ -77,11 +106,24 @@
</template> </template>
<script> <script>
import { operates, operations, tableTitle, searchConfig } from "./configs/list"; import {
operates,
viewButton,
downloadButton,
deleteButton,
tableTitle,
searchConfig,
} from "./configs/list";
import { records } from "./mock"; import { records } from "./mock";
import UploadDialog from "@/components/UploadDialog"; import UploadDialog from "@/components/UploadDialog";
import PreviewDialog from "./components/PreviewDialog"; import PreviewDialog from "./components/PreviewDialog";
import { getMattingList } from "@/api/matting"; import { Debounce } from "@/utils/index";
import {
getMattingList,
getMattingDetail,
downFileByMattingIds,
deleteMattingRecord,
} from "@/api/matting";
export default { export default {
components: { components: {
UploadDialog, UploadDialog,
...@@ -101,10 +143,9 @@ export default { ...@@ -101,10 +143,9 @@ export default {
importRecordVisible: false, //上传记录 importRecordVisible: false, //上传记录
imgList: [], imgList: [],
operates, operates,
operations,
tableTitle, tableTitle,
currentUploadType: ".zip", //当前上传的文件类型 currentUploadType: ".zip", //当前上传的文件类型
currentPreviewItem: {}, //当前点击的表格项目 previewInfo: {}, //当前点击预览的表格项目
TYPE_IMG: "0", //单个图片文件 TYPE_IMG: "0", //单个图片文件
TYPE_ZIP: "1", //zip文件 TYPE_ZIP: "1", //zip文件
uploadOptions: { uploadOptions: {
...@@ -115,10 +156,33 @@ export default { ...@@ -115,10 +156,33 @@ export default {
uploadTitleKey: "title", uploadTitleKey: "title",
}, },
searchParams: {}, searchParams: {},
multiSelection: [],
}; };
}, },
async created() { computed: {
// this.loadData(); multiDisabled() {
return this.multiSelection.length == 0;
},
getOperations(status) {
return (status) => {
if (status == 1) {
return [viewButton, downloadButton, deleteButton];
} else {
const newViewButton = {
...viewButton,
disabled: true,
};
const newDownloadButton = {
...downloadButton,
disabled: true,
};
return [newViewButton, newDownloadButton, deleteButton];
}
};
},
},
created() {
this.loadData();
}, },
methods: { methods: {
async search(form) { async search(form) {
...@@ -126,7 +190,7 @@ export default { ...@@ -126,7 +190,7 @@ export default {
this.resetPage(); this.resetPage();
this.loadData(form); this.loadData(form);
}, },
// 清除分页到初始状态
resetPage() { resetPage() {
this.list.current = 1; this.list.current = 1;
}, },
...@@ -134,7 +198,7 @@ export default { ...@@ -134,7 +198,7 @@ export default {
this.searchParams = {}; this.searchParams = {};
this.loadData(); this.loadData();
}, },
// 加载表格数据
async loadData(form) { async loadData(form) {
const { current, size } = this.list; const { current, size } = this.list;
var params = { var params = {
...@@ -152,28 +216,82 @@ export default { ...@@ -152,28 +216,82 @@ export default {
}, },
handleCommand(type) { handleCommand(type) {
this.uploadOptions.compressFlag = type; this.uploadOptions.compressFlag = type;
this.openDialog("UploadDialog"); this.$appCommon.openDialog(this, "UploadDialog");
},
openDialog(refName) {
this.$refs[refName].visible = true;
}, },
async handleOperation(value, row) { async handleOperation(value, row) {
switch (value.type) { switch (value.type) {
case "view": case "view":
this.currentPreviewItem = row; this.handleView(row);
this.$appCommon.openDialog(this, "PreviewDialog");
break; break;
case "download": case "download":
console.log("download"); const { title, mattingId } = row;
const ids = [mattingId];
this.downloadByRecordId(ids, title);
break; break;
case "delete": case "delete":
console.log("delete"); this.handleDeleteRow(row);
break; break;
} }
}, },
async handleView(row) {
const { mattingId } = row;
const params = {
mattingId,
};
const res = await getMattingDetail(params);
if (res.code == 0) {
this.previewInfo = res.data;
this.$appCommon.openDialog(this, "PreviewDialog");
}
},
handleDeleteRow(row) {
const ids = [row.mattingId];
this.deleteByRecordsId(ids);
},
handleMultiDelete() {
const ids = this.multiSelection.map((item) => {
return item.mattingId;
});
this.deleteByRecordsId(ids);
},
handleMultiDownload() {
const ids = this.multiSelection.map((item) => {
return item.mattingId;
});
this.downloadByRecordId(ids);
},
deleteByRecordsId: Debounce(async function (ids) {
const res = await deleteMattingRecord(ids);
if (res.code == 0) {
this.$message.success("删除成功!");
this.loadData();
}
}, 600),
downloadByRecordId: Debounce(async function (ids, name = "") {
const params = ids;
const url =
process.env.VUE_APP_BASE_API +
"/bizMattingRecords/downFileByMattingIds";
const method = "post";
const fileName = name + "_智能抠图处理后文件";
const suffix = "zip";
const opitons = {
url,
method,
fileName,
suffix,
data: params,
};
await this.$file.downloadBlob(opitons);
}, 600),
// 关闭预览图片 // 关闭预览图片
closeImgViewer() { closeImgViewer() {
this.imgViewerVisible = false; this.imgViewerVisible = false;
...@@ -186,7 +304,7 @@ export default { ...@@ -186,7 +304,7 @@ export default {
// 多选 // 多选
handleSelectionChange(val) { handleSelectionChange(val) {
this.multipleSelection = val; this.multiSelection = val;
}, },
// 改变页容量 // 改变页容量
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论