Browse Source

新增产品图片上传

flowtest
zhouhaibin 5 months ago
parent
commit
628f5a9ae8
  1. 8
      src/modules/costManagement/components/costTypeComponents.vue
  2. 2
      src/modules/productManagement/api/index.ts
  3. 106
      src/modules/productManagement/components/uploadImage.vue
  4. 78
      src/modules/productManagement/view/companyProducts/index.vue
  5. 74
      src/modules/productManagement/view/personProducts/index.vue
  6. 25
      src/modules/productManagement/view/supplierProducts/index.vue
  7. 4
      src/modules/support/api/index.ts

8
src/modules/costManagement/components/costTypeComponents.vue

@ -143,7 +143,13 @@ export default {
label: '产品描述', label: '产品描述',
labelWidth: 120, labelWidth: 120,
//editDisabled: true // //editDisabled: true //
display: false // display: false ,//,
overHidden: true,
},
image: {
label: '图片',
labelWidth: 120,
type: 'upload'
}, },
remarks: { remarks: {
label: '备注', label: '备注',

2
src/modules/productManagement/api/index.ts

@ -27,7 +27,7 @@ export const supplierInformation = Object.assign({}, COMMON_METHOD, {
// 厂商产品管理 // 厂商产品管理
export const supplierProducts = Object.assign({}, COMMON_METHOD, { export const supplierProducts = Object.assign({}, COMMON_METHOD, {
serveUrl: '/' + moduleName + '/' + 'supplierProducts' + '/' serveUrl: '/' + moduleName + '/' + 'supplierProducts' + '/',
}) })
// 公司产品 // 公司产品

106
src/modules/productManagement/components/uploadImage.vue

@ -0,0 +1,106 @@
<template>
<el-upload
v-model:file-list="fileList"
class="upload-demo"
action
:on-preview="handlePreview"
:on-remove="handleRemove"
list-type="picture"
:limit="1"
:http-request="ImgUploadSectionFile"
:before-upload="beforeAvatarUpload"
:on-change="handleEditChange"
:on-exceed="handleExceed"
accept=".png, .jpg"
>
<el-button type="primary">上传图片</el-button>
<template #tip>
<div class="el-upload__tip">支持 jpg/png 最大尺寸为10Mb</div>
</template>
</el-upload>
<el-dialog v-model="dialogVisible">
<img w-full :src="dialogImageUrl" alt="Preview Image" />
</el-dialog>
</template>
<script lang="ts" setup>
import { ref,defineEmits,defineProps} from 'vue'
import { ElMessage } from 'element-plus'
import type { UploadProps, UploadUserFile } from 'element-plus'
const propsData= defineProps(["modelValue","moduleParam"])
const emits= defineEmits(['update:modelValue'])
const fileList = ref<UploadUserFile[]>([])
let dialogVisible = ref(false)
let dialogImageUrl = ref()
if(propsData.modelValue){
fileList.value.push({url:propsData.modelValue,name:propsData.modelValue.split('/')[propsData.modelValue.split('/').length-1]})
console.log(fileList.value)
}
// const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
// console.log(uploadFile, uploadFiles)
// }
const handlePreview: UploadProps['onPreview'] = (file) => {
console.log(file)
dialogImageUrl.value = file.url
dialogVisible.value = true
}
//
function handleRemove(file, fileList) {
if (fileList.length === 0) {
fileList = []
} else {
let dl = fileList.indexOf(file)
fileList.splice(dl, 1)
}
console.log('remove', file, fileList)
// hideUploadEdit = fileList.length >= limitNum
}
// on-change
function handleEditChange(file, fileList) {
console.log('file:', file, fileList)
// hideUploadEdit = fileList.length >= limitNum
// console.log("this.fileList:", this.fileList);
// console.log("this.hideUploadEdit:", this.hideUploadEdit);
}
// http-request
function ImgUploadSectionFile(param) {
console.log('param', param)
emits("update:modelValue",param.file)
}
// before-upload
// false Promise reject
function beforeAvatarUpload(file) {
const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'
const isLt2M = file.size / 1024 / 1024 < 10
if (!isJPG) {
ElMessage.error('上传图片只能是 JPG 或 PNG 格式!')
}
if (!isLt2M) {
ElMessage.error('上传图片大小不能超过 10MB!')
}
return isJPG && isLt2M
}
function handleExceed() {
ElMessage.warning('最多只能上传一个文件')
}
</script>
<!-- :limit="limitNum" //
:class="{hide:hideUploadEdit}" //
:on-remove="handleRemove" //
:on-change="handleEditChange" //()
:http-request="ImgUploadSectionFile" //
:before-upload="beforeAvatarUpload" //
:with-credentials="true" // cookie
:auto-upload="true" //(false)
accept=".png, .jpg" //
action="" //url
list-type="picture-card" //
:file-list="fileList" //
-->

78
src/modules/productManagement/view/companyProducts/index.vue

@ -56,12 +56,17 @@
<template #modelId-form="{}"> <template #modelId-form="{}">
<product-model-components v-model="formData.modelId" :module-param="moduleParam" /> <product-model-components v-model="formData.modelId" :module-param="moduleParam" />
</template> </template>
<template #image-form="{}">
<uploadImage v-model="formData.image" :module-param="moduleParam" />
</template>
</avue-crud> </avue-crud>
</template> </template>
<script setup> <script setup>
import { ref, getCurrentInstance, reactive } from 'vue' import { ref, getCurrentInstance, reactive } from 'vue'
import supplierInformationComponents from '@/modules/productManagement/components/supplierInformationComponents.vue' import supplierInformationComponents from '@/modules/productManagement/components/supplierInformationComponents.vue'
import productModelComponents from '@/modules/productManagement/components/productModelComponents.vue' import productModelComponents from '@/modules/productManagement/components/productModelComponents.vue'
import uploadImage from '@/modules/productManagement/components/uploadImage.vue'
import apiIndex from '@/api/index'
//this //this
let { proxy } = getCurrentInstance() let { proxy } = getCurrentInstance()
const option = ref(null) const option = ref(null)
@ -105,8 +110,8 @@ option.value = {
labelWidth: 120, labelWidth: 120,
prop: 'productName', //sProductName prop: 'productName', //sProductName
search: true, search: true,
html:true, html: true,
formatter:(val)=>{ formatter: (val) => {
return val.productName return val.productName
}, },
searchLabelWidth: 120 searchLabelWidth: 120
@ -148,8 +153,8 @@ option.value = {
labelWidth: 120, labelWidth: 120,
prop: 'productSpecifications', prop: 'productSpecifications',
//editDisabled: true // //editDisabled: true //
html:true, html: true,
formatter:(val)=>{ formatter: (val) => {
return val.productSpecifications return val.productSpecifications
}, },
display: false // display: false //
@ -158,27 +163,33 @@ option.value = {
label: '图片', label: '图片',
labelWidth: 120, labelWidth: 120,
prop: 'image', prop: 'image',
type: 'img', type: 'img'
// httpRequest: (file, column) => {
// console.log("image",file, column)
// const formData = new FormData()
// formData.append('image', file.file)
// apiIndex.support.attachment.uploadImageReturnUrl(formData)
// }
}, },
{ {
label: '品牌', label: '品牌',
labelWidth: 120, labelWidth: 120,
prop: 'brand', prop: 'brand'
}, },
{ {
label: '单位', label: '单位',
labelWidth: 120, labelWidth: 120,
prop: 'unit', prop: 'unit'
}, },
{ {
label: '除税价格', label: '除税价格',
labelWidth: 120, labelWidth: 120,
prop: 'exTaxPrice', prop: 'exTaxPrice'
}, },
{ {
label: '税率', label: '税率',
labelWidth: 120, labelWidth: 120,
prop: 'taxrate', prop: 'taxrate'
}, },
{ {
label: '信息来源', label: '信息来源',
@ -195,27 +206,46 @@ option.value = {
] ]
} }
data.value = [] data.value = []
function rowSave(row, done, loading) { async function rowSave(row, done, loading) {
api.add(row).then(() => { // url
done() console.log(row.image)
onLoad() const formData = new FormData()
}).catch(() => { formData.append('image', row.image)
loading() let res = await apiIndex.support.attachment.uploadImageReturnUrl(formData)
row.image = res.data
}) //
api
.add(row)
.then(() => {
done()
onLoad()
})
.catch(() => {
loading()
})
} }
function rowDel(row, index) { function rowDel(row, index) {
api.remove(row.id) api.remove(row.id)
onLoad() onLoad()
} }
function rowUpdate(row, index, done, loading) { async function rowUpdate(row, index, done, loading) {
api.modify(row).then(() => { if (typeof row.image === 'object') {
done() console.log(row.image)
onLoad() const formData = new FormData()
}).catch(() => { formData.append('image', row.image)
loading() let res = await apiIndex.support.attachment.uploadImageReturnUrl(formData)
row.image = res.data
}
}) api
.modify(row)
.then(() => {
done()
onLoad()
})
.catch(() => {
loading()
})
// done() // done()
} }
function onLoad() { function onLoad() {

74
src/modules/productManagement/view/personProducts/index.vue

@ -56,12 +56,18 @@
<template #modelId-form="{}"> <template #modelId-form="{}">
<product-model-components v-model="formData.modelId" :module-param="moduleParam" /> <product-model-components v-model="formData.modelId" :module-param="moduleParam" />
</template> </template>
<template #image-form="{}">
<uploadImage v-model="formData.image" :module-param="moduleParam" />
</template>
</avue-crud> </avue-crud>
</template> </template>
<script setup> <script setup>
import { ref, getCurrentInstance, reactive } from 'vue' import { ref, getCurrentInstance, reactive } from 'vue'
import supplierInformationComponents from '@/modules/productManagement/components/supplierInformationComponents.vue' import supplierInformationComponents from '@/modules/productManagement/components/supplierInformationComponents.vue'
import productModelComponents from '@/modules/productManagement/components/productModelComponents.vue' import productModelComponents from '@/modules/productManagement/components/productModelComponents.vue'
import apiIndex from '@/api/index'
import uploadImage from '@/modules/productManagement/components/uploadImage.vue'
//this //this
let { proxy } = getCurrentInstance() let { proxy } = getCurrentInstance()
const option = ref(null) const option = ref(null)
@ -105,8 +111,8 @@ option.value = {
labelWidth: 120, labelWidth: 120,
prop: 'productName', //sProductName prop: 'productName', //sProductName
search: true, search: true,
html:true, html: true,
formatter:(val)=>{ formatter: (val) => {
return val.productName return val.productName
}, },
searchLabelWidth: 120 searchLabelWidth: 120
@ -148,8 +154,8 @@ option.value = {
labelWidth: 120, labelWidth: 120,
prop: 'productSpecifications', prop: 'productSpecifications',
//editDisabled: true // //editDisabled: true //
html:true, html: true,
formatter:(val)=>{ formatter: (val) => {
return val.productSpecifications return val.productSpecifications
}, },
display: false // display: false //
@ -158,27 +164,27 @@ option.value = {
label: '图片', label: '图片',
labelWidth: 120, labelWidth: 120,
prop: 'image', prop: 'image',
type: 'img', type: 'img'
}, },
{ {
label: '品牌', label: '品牌',
labelWidth: 120, labelWidth: 120,
prop: 'brand', prop: 'brand'
}, },
{ {
label: '单位', label: '单位',
labelWidth: 120, labelWidth: 120,
prop: 'unit', prop: 'unit'
}, },
{ {
label: '除税价格', label: '除税价格',
labelWidth: 120, labelWidth: 120,
prop: 'exTaxPrice', prop: 'exTaxPrice'
}, },
{ {
label: '税率', label: '税率',
labelWidth: 120, labelWidth: 120,
prop: 'taxrate', prop: 'taxrate'
}, },
{ {
label: '信息来源', label: '信息来源',
@ -195,27 +201,45 @@ option.value = {
] ]
} }
data.value = [] data.value = []
function rowSave(row, done, loading) { async function rowSave(row, done, loading) {
api.add(row).then(() => { if (typeof row.image === 'object') {
done() console.log(row.image)
onLoad() const formData = new FormData()
}).catch(() => { formData.append('image', row.image)
loading() let res = await apiIndex.support.attachment.uploadImageReturnUrl(formData)
row.image = res.data
}) }
api
.add(row)
.then(() => {
done()
onLoad()
})
.catch(() => {
loading()
})
} }
function rowDel(row, index) { function rowDel(row, index) {
api.remove(row.id) api.remove(row.id)
onLoad() onLoad()
} }
function rowUpdate(row, index, done, loading) { async function rowUpdate(row, index, done, loading) {
api.modify(row).then(() => { if (typeof row.image === 'object') {
done() console.log(row.image)
onLoad() const formData = new FormData()
}).catch(() => { formData.append('image', row.image)
loading() let res = await apiIndex.support.attachment.uploadImageReturnUrl(formData)
row.image = res.data
}) }
api
.modify(row)
.then(() => {
done()
onLoad()
})
.catch(() => {
loading()
})
} }
function onLoad() { function onLoad() {
pageInfo.pageNum = page.currentPage pageInfo.pageNum = page.currentPage

25
src/modules/productManagement/view/supplierProducts/index.vue

@ -57,12 +57,17 @@
<template #modelId-form="{}"> <template #modelId-form="{}">
<product-model-components v-model="formData.modelId" :module-param="moduleParam" /> <product-model-components v-model="formData.modelId" :module-param="moduleParam" />
</template> </template>
<template #image-form="{}">
<uploadImage v-model="formData.image" :module-param="moduleParam" />
</template>
</avue-crud> </avue-crud>
</template> </template>
<script setup> <script setup>
import { ref, getCurrentInstance, reactive } from 'vue' import { ref, getCurrentInstance, reactive } from 'vue'
import supplierInformationComponents from '@/modules/productManagement/components/supplierInformationComponents.vue' import supplierInformationComponents from '@/modules/productManagement/components/supplierInformationComponents.vue'
import productModelComponents from '@/modules/productManagement/components/productModelComponents.vue' import productModelComponents from '@/modules/productManagement/components/productModelComponents.vue'
import apiIndex from '@/api/index'
import uploadImage from '@/modules/productManagement/components/uploadImage.vue'
//this //this
let { proxy } = getCurrentInstance() let { proxy } = getCurrentInstance()
const option = ref(null) const option = ref(null)
@ -163,7 +168,7 @@ option.value = {
label: '图片', label: '图片',
labelWidth: 120, labelWidth: 120,
prop: 'image', prop: 'image',
type: 'img', type: 'upload',
}, },
{ {
label: '品牌', label: '品牌',
@ -203,7 +208,14 @@ option.value = {
] ]
} }
data.value = [] data.value = []
function rowSave(row, done, loading) { async function rowSave(row, done, loading) {
if (typeof row.image === 'object') {
console.log(row.image)
const formData = new FormData()
formData.append('image', row.image)
let res = await apiIndex.support.attachment.uploadImageReturnUrl(formData)
row.image = res.data
}
api api
.add(row) .add(row)
.then((res) => { .then((res) => {
@ -218,7 +230,14 @@ function rowDel(row, index) {
api.remove(row.id) api.remove(row.id)
onLoad() onLoad()
} }
function rowUpdate(row, index, done, loading) { async function rowUpdate(row, index, done, loading) {
if (typeof row.image === 'object') {
console.log(row.image)
const formData = new FormData()
formData.append('image', row.image)
let res = await apiIndex.support.attachment.uploadImageReturnUrl(formData)
row.image = res.data
}
api api
.modify(row) .modify(row)
.then((res) => { .then((res) => {

4
src/modules/support/api/index.ts

@ -54,6 +54,10 @@ export const attachment = Object.assign({}, COMMON_METHOD, {
// 上传图片 // 上传图片
uploadImage(param) { uploadImage(param) {
return request.upload({ url: this.serveUrl + 'uploadImage', data: param }) return request.upload({ url: this.serveUrl + 'uploadImage', data: param })
},
uploadImageReturnUrl(param){
return request.upload({ url: this.serveUrl + 'uploadImageReturnUrl', data: param })
} }
}) })

Loading…
Cancel
Save