Browse Source

新增产品图片上传

flowtest
zhouhaibin 3 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. 80
      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: '产品描述',
labelWidth: 120,
//editDisabled: true //
display: false //
display: false ,//,
overHidden: true,
},
image: {
label: '图片',
labelWidth: 120,
type: 'upload'
},
remarks: {
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, {
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" //
-->

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

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

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

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

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

@ -57,12 +57,17 @@
<template #modelId-form="{}">
<product-model-components v-model="formData.modelId" :module-param="moduleParam" />
</template>
<template #image-form="{}">
<uploadImage v-model="formData.image" :module-param="moduleParam" />
</template>
</avue-crud>
</template>
<script setup>
import { ref, getCurrentInstance, reactive } from 'vue'
import supplierInformationComponents from '@/modules/productManagement/components/supplierInformationComponents.vue'
import productModelComponents from '@/modules/productManagement/components/productModelComponents.vue'
import apiIndex from '@/api/index'
import uploadImage from '@/modules/productManagement/components/uploadImage.vue'
//this
let { proxy } = getCurrentInstance()
const option = ref(null)
@ -163,7 +168,7 @@ option.value = {
label: '图片',
labelWidth: 120,
prop: 'image',
type: 'img',
type: 'upload',
},
{
label: '品牌',
@ -203,7 +208,14 @@ option.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
.add(row)
.then((res) => {
@ -218,7 +230,14 @@ function rowDel(row, index) {
api.remove(row.id)
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
.modify(row)
.then((res) => {

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

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

Loading…
Cancel
Save