From 91c67198a84e9c0a76cc0154fbebf62813c1de26 Mon Sep 17 00:00:00 2001 From: jinlin <jinlin> Date: 星期三, 13 三月 2024 18:06:09 +0800 Subject: [PATCH] 修改 --- web/src/views/modules/sysPictureBase/SysPictureBase-AddOrUpdate.vue | 63 +++++++++++++++++++++++++++---- 1 files changed, 54 insertions(+), 9 deletions(-) diff --git a/web/src/views/modules/sysPictureBase/SysPictureBase-AddOrUpdate.vue b/web/src/views/modules/sysPictureBase/SysPictureBase-AddOrUpdate.vue index 09ca888..49b5bed 100644 --- a/web/src/views/modules/sysPictureBase/SysPictureBase-AddOrUpdate.vue +++ b/web/src/views/modules/sysPictureBase/SysPictureBase-AddOrUpdate.vue @@ -10,19 +10,24 @@ <zt-form-item label="鍥剧墖鍚嶇О" prop="name" rules="required"> <el-input v-model="dataForm.name"></el-input> </zt-form-item> - <zt-form-item label="妫�绱㈠叧閿瓧" prop="contentType" > + <zt-form-item label="妫�绱㈠叧閿瓧" prop="contentType"> <el-input v-model="dataForm.contentType"></el-input> </zt-form-item> - <zt-form-item label="绯荤粺鏍囪瘑" prop="systemMark" rules="required"> + <zt-form-item label="绯荤粺鏍囪瘑" prop="systemMark"> <zt-dict v-model="dataForm.systemMark" dict="product"></zt-dict> </zt-form-item> <zt-form-item label="鎺掑簭" prop="sortNo"> - <el-input v-model="dataForm.sortNo" :readonly="readonly" @input=""></el-input> + <el-input v-model="dataForm.sortNo" :readonly="readonly" @input=""></el-input> </zt-form-item> + <div class="el-flex img-src" style="height: 20px"> <el-form-item class="marginTopAndMarginBottom" style="width: 100%"> - <config-uploader :lineHeight="true" busi-type="sys_picture" model-name="dataForm" :dataForm="dataForm" - v-model="dataForm.files"/> + <!--<config-uploader :lineHeight="true" busi-type="sys_picture" model-name="dataForm" :dataForm="dataForm" + v-model="dataForm.files"/>--> + <el-upload :limit="1" :http-request="httpRequest" :before-upload="beforeUpload" :on-exceed="handleExceed"> + <el-button slot="trigger" size="small" type="primary">閫夊彇鏂囦欢</el-button> + </el-upload> + <el-image v-if="dataForm.id" :src="url+dataForm.id" style="height: 50px;width: 50px"></el-image> </el-form-item> </div> </el-form> @@ -30,9 +35,13 @@ </template> <script> + import Cookies from "js-cookie"; + export default { data() { return { + url: `${window.SITE_CONFIG['apiURL']}/sysPictureBase/getProductImg?token=${Cookies.get('token')}&id=`, + fileList: [], dataForm: { id: '', type: '', @@ -43,24 +52,59 @@ sortNo: '', remark: '' }, - readonly:{ + readonly: { type: Boolean, default: false }, } }, methods: { + httpRequest(option) { + this.fileList.length = 0 + this.fileList.push(option) + }, + // 涓婁紶鍓嶅鐞� + beforeUpload(file) { + let fileSize = file.size + const FIVE_M = 5 * 1024 * 1024; + //澶т簬5M锛屼笉鍏佽涓婁紶 + if (fileSize > FIVE_M) { + this.$message.error("鏈�澶т笂浼�5M") + return false + } + }, + // 鏂囦欢鏁伴噺杩囧鏃舵彁閱� + handleExceed() { + this.$message({type: 'error', message: '鏈�澶氭敮鎸�1涓檮浠朵笂浼�'}) + }, // 鑾峰彇淇℃伅 async getInfo() { - let res = await this.$http.get(`/sysPictureBase/SysPictureBase/${this.dataForm.id}`) + let res = await this.$http.get(`/sysPictureBase/${this.dataForm.id}`) this.dataForm = { ...this.dataForm, ...res.data } + console.log(this.dataForm, 'async getInfo()') }, // 琛ㄥ崟鎻愪氦 async formSubmit() { - let res = await this.$http[!this.dataForm.id ? 'post' : 'put']('/sysPictureBase/SysPictureBase/', this.dataForm) + console.log(this.dataForm, 'async formSubmit()') + // 浣跨敤form琛ㄥ崟鐨勬暟鎹牸寮� + const params = new FormData() + // 灏嗕笂浼犳枃浠舵暟缁勪緷娆℃坊鍔犲埌鍙傛暟paramsData涓� + this.fileList.forEach((x) => { + params.append('file', x.file) + }); + // 灏嗚緭鍏ヨ〃鍗曟暟鎹坊鍔犲埌params琛ㄥ崟涓� + params.append('id', this.dataForm.id) + params.append('type', this.dataForm.type) + params.append('subType', this.dataForm.subType) + params.append('name', this.dataForm.name) + params.append('contentType', this.dataForm.contentType) + params.append('systemMark', this.dataForm.systemMark) + params.append('sortNo', this.dataForm.sortNo) + console.log(params, 'async formSubmit()') + let res = await this.$http.post('/sysPictureBase/save', params) if (res.success) { await this.$tip.success() this.$refs.dialog.close() @@ -74,7 +118,8 @@ .img-sc > .el-form-item > .el-form-item__content { width: 100%; } - .marginTopAndMarginBottom { + + .marginTopAndMarginBottom { margin-top: 10px !important; margin-bottom: 0 !important; } -- Gitblit v1.9.1