diff --git a/src/api/base/project.js b/src/api/base/project.js index 7736c11..806acce 100644 --- a/src/api/base/project.js +++ b/src/api/base/project.js @@ -1,6 +1,6 @@ import request from '@/utils/request' -// 查询岗位列表 +// 查询列表 export function listProject(query) { return request({ url: '/bracelet/project/list', @@ -9,7 +9,7 @@ export function listProject(query) { }) } -// 查询岗位详细 +// 查询详细 export function getProject(projectId) { return request({ url: '/bracelet/project/' + projectId, @@ -17,18 +17,26 @@ export function getProject(projectId) { }) } -// 新增岗位 +// 新增 export function addProject(data) { return request({ - url: '/bracelet/project', + headers: { // 修改请求头 + 'decrypt': 'decrypt', + 'Content-Type': 'multipart/form-data' + }, + url: '/bracelet/project/addtemp', method: 'post', data: data }) } -// 修改岗位 +// 修改 export function updateProject(data) { return request({ + headers: { // 修改请求头 + 'decrypt': 'decrypt', + 'Content-Type': 'multipart/form-data' + }, url: '/bracelet/project', method: 'put', data: data diff --git a/src/views/base/project/index.vue b/src/views/base/project/index.vue index f3a89c9..282a7a6 100644 --- a/src/views/base/project/index.vue +++ b/src/views/base/project/index.vue @@ -75,7 +75,14 @@ - + + + + @@ -107,7 +114,7 @@ /> - + @@ -122,6 +129,23 @@ + + + @@ -130,6 +154,15 @@ 取 消 + + + + + + + + + @@ -172,6 +205,16 @@ export default { }, // 表单参数 form: {}, + //删除图片fileId + delFileIdList:[], + //图片上传 + fileList: [], + //图片查看弹窗 + dialogImageUrl: '', + dialogVisible: false, + //多图片查看弹窗 + dialogImageUrls: [], + dialogVisibles: false, // 表单校验 rules: { projectDepartName: [ @@ -197,6 +240,12 @@ export default { created() { this.getList(); }, + computed: { + //图片上传1张后,隐藏上传框 + uploadDisabled() { + return this.fileList.length > 0 + }, + }, methods: { /** 查询岗位列表 */ getList() { @@ -210,6 +259,7 @@ export default { // 取消按钮 cancel() { this.open = false; + this.fileList=[]; this.reset(); }, // 表单重置 @@ -242,32 +292,101 @@ export default { }, /** 新增按钮操作 */ handleAdd() { + this.fileList = [] this.reset(); this.open = true; this.title = "添加项目"; }, /** 修改按钮操作 */ handleUpdate(row) { + this.fileList = [] this.reset(); - const projectId = row.projectId || this.ids + const projectId = row.projectId + getProject(projectId).then(response => { - this.form = response.data; - this.open = true; - this.title = "修改项目"; - }); + + this.form = response.data; + response.data.fileList.forEach(item => { + this.fileList.push({ + fileId: item.filePath, + url: item.bast64Image + }) + }); + response.data.fileList = []; + + setTimeout(()=>{ + this.open = true; + this.title = "修改项目"; + },100) + + }); + }, + // 图片上传 + handleChange(file, fileList) { + console.log(file) + // this.$refs["form"].clearValidate() + this.fileList = fileList; + }, + handleRemove(file, fileList) { + let sum = 0 + this.fileList.forEach((item, index) => { + if (item.uid == file.uid) { + sum = index + } + }) + this.delFileIdList.push(this.fileList[sum].fileId) + console.log(this.delFileIdList) + this.fileList.splice(sum, 1) + }, + //上传组件-图片查看 + picturePreview(file) { + console.log(file) + this.dialogImageUrl = file.url + this.dialogVisible = true + }, + //多图片查看 + picturesPreview(fileList) { + console.log(fileList) + this.dialogImageUrls = fileList; + this.dialogVisibles = true; + }, + //提交时循环fileList 获取raw文件 + getFileData() { + const file = [] + this.fileList.forEach(item => { + if (item?.hasOwnProperty('raw')) { + file.push(item.raw) + } + }) + return { file } }, /** 提交按钮 */ submitForm: function() { this.$refs["form"].validate(valid => { if (valid) { if (this.form.projectId != undefined) { - updateProject(this.form).then(response => { + const reqData = new FormData(); + this.form.delFileIdList = this.delFileIdList; + reqData.append('params', JSON.stringify(this.form)) + const { file } = this.getFileData() + file.forEach(item => { + reqData.append('file', item) + }) + updateProject(reqData).then(response => { this.$modal.msgSuccess("修改成功"); this.open = false; + this.fileList=[]; this.getList(); }); } else { - addProject(this.form).then(response => { + console.log(this.form) + const reqData = new FormData() + reqData.append('params', JSON.stringify(this.form)) + const { file } = this.getFileData() + file.forEach(item => { + reqData.append('file', item) + }) + addProject(reqData).then(response => { this.$modal.msgSuccess("新增成功"); this.open = false; this.getList(); diff --git a/src/views/base/staff/index.vue b/src/views/base/staff/index.vue index 9680c34..510adf7 100644 --- a/src/views/base/staff/index.vue +++ b/src/views/base/staff/index.vue @@ -420,11 +420,14 @@ }, handleRemove(file, fileList) { let sum = 0 + console.log(111111) + console.log(this.fileList) this.fileList.forEach((item, index) => { if (item.uid == file.uid) { sum = index } }) + this.fileList.splice(sum, 1) }, //上传组件-图片查看 @@ -451,6 +454,7 @@ name: response.data.fileId, url: response.data.base64Url }) + this.form.fileName = response.data.fileId; setTimeout(()=>{ this.open = true;