图片字段改为 序列化数组

This commit is contained in:
szdot 2024-04-26 14:04:01 +08:00
parent 45c0e8b645
commit 4e8605989a
9 changed files with 49 additions and 19 deletions

View File

@ -6,7 +6,7 @@
</el-option> </el-option>
<el-option v-for="item in categoryListArr" :key="item.id" :label="item.name" :value="item.path"> <el-option v-for="item in categoryListArr" :key="item.id" :label="item.name" :value="item.path">
<el-avatar v-if="item.photo != ''" class="vm" shape="square" :size="25" <el-avatar v-if="item.photo != ''" class="vm" shape="square" :size="25"
:src="$store.state.settings.host + '/Data/UploadFiles/category/' + item.photo"> :src="item.photo[0]">
</el-avatar> </el-avatar>
<el-avatar v-else :size="25" class="vm" shape="square" icon="iconfont icon-tuxiang"></el-avatar> <el-avatar v-else :size="25" class="vm" shape="square" icon="iconfont icon-tuxiang"></el-avatar>
<span v-for="element in item.pathLen" :key="element" class="m-l-30"></span> <span v-for="element in item.pathLen" :key="element" class="m-l-30"></span>

View File

@ -1,4 +1,9 @@
module.exports = { const host = 'https://www.szdot.top'
const baseURL = host + '/flycube.php'
const listPath = host + '/Data/UploadFiles/category/'
const spuPath = host + '/Data/UploadFiles/spu/'
const skuPath = host + '/Data/UploadFiles/sku/'
export default {
/** /**
* @description: 全局title * @description: 全局title
@ -13,8 +18,11 @@ module.exports = {
* api小程序后台接口路径 * api小程序后台接口路径
* api登录接口路径 * api登录接口路径
*/ */
host: 'https://szdot.top', host: host,
baseURL: 'https://szdot.top/flycube.php', baseURL: baseURL,
listPath: listPath,
spuPath: spuPath,
skuPath: skuPath,
apiPlanePath: '/mpApi/Plane/', apiPlanePath: '/mpApi/Plane/',
apiAdminPath: '/mpApi/Admin/', apiAdminPath: '/mpApi/Admin/',
apiLoginPath: '/mpApi/Login/', apiLoginPath: '/mpApi/Login/',

View File

@ -205,7 +205,6 @@ const store = new Vuex.Store({
* @return {*} 服务器返回值 * @return {*} 服务器返回值
*/ */
async fetchSaveAdmin ({ dispatch }, form) { async fetchSaveAdmin ({ dispatch }, form) {
console.log(form)
const params = new URLSearchParams() const params = new URLSearchParams()
params.append('id', form.id) params.append('id', form.id)
params.append('shop_id', form.shop_id) params.append('shop_id', form.shop_id)
@ -558,6 +557,12 @@ const store = new Vuex.Store({
async fetchCategoryList ({ commit }) { async fetchCategoryList ({ commit }) {
const res = await api.get('getCategoryList', 'Admin') const res = await api.get('getCategoryList', 'Admin')
if (res.data.status === 1) { if (res.data.status === 1) {
res.data.categoryList.forEach((category, index) => {
category.photo = JSON.parse(category.photo)// 反序列化 photo字段
category.photo.forEach((photo, i) => {
res.data.categoryList[index].photo[i] = settings.state.listPath + photo // 把绝对路径加上
})
})
commit('setCategoryList', res.data.categoryList) commit('setCategoryList', res.data.categoryList)
} else { } else {
commit('setCategoryList', []) commit('setCategoryList', [])
@ -637,6 +642,12 @@ const store = new Vuex.Store({
async fetchSpuList ({ commit }) { async fetchSpuList ({ commit }) {
const res = await api.get('getSpuList', 'Admin') const res = await api.get('getSpuList', 'Admin')
if (res.data.status === 1) { if (res.data.status === 1) {
res.data.spuList.forEach((spu, index) => {
spu.photo = JSON.parse(spu.photo)// 反序列化 photo字段
spu.photo.forEach((photo, i) => {
res.data.spuList[index].photo[i] = settings.state.spuPath + photo // 把绝对路径加上
})
})
commit('setSpuList', res.data.spuList) commit('setSpuList', res.data.spuList)
} else { } else {
commit('setSpuList', []) commit('setSpuList', [])
@ -804,6 +815,12 @@ const store = new Vuex.Store({
async fetchSkuList ({ commit }) { async fetchSkuList ({ commit }) {
const res = await api.get('getSkuList', 'Admin') const res = await api.get('getSkuList', 'Admin')
if (res.data.status === 1) { if (res.data.status === 1) {
res.data.skuList.forEach((sku, index) => {
sku.photo = JSON.parse(sku.photo)// 反序列化 photo字段
sku.photo.forEach((photo, i) => {
res.data.skuList[index].photo[i] = settings.state.skuPath + photo // 把绝对路径加上
})
})
commit('setSkuList', res.data.skuList) commit('setSkuList', res.data.skuList)
} else { } else {
commit('setSkuList', []) commit('setSkuList', [])

View File

@ -4,6 +4,9 @@ const {
title, title,
host, host,
baseURL, baseURL,
listPath,
spuPath,
skuPath,
apiPlanePath, apiPlanePath,
apiAdminPath, apiAdminPath,
apiLoginPath, apiLoginPath,
@ -17,6 +20,9 @@ const state = {
title: title, title: title,
host: host, host: host,
baseURL: baseURL, baseURL: baseURL,
listPath: listPath,
spuPath: spuPath,
skuPath: skuPath,
apiPlanePath: apiPlanePath, apiPlanePath: apiPlanePath,
apiAdminPath: apiAdminPath, apiAdminPath: apiAdminPath,
apiLoginPath: apiLoginPath, apiLoginPath: apiLoginPath,

View File

@ -73,8 +73,8 @@
:before-upload="beforeAvatarUpload"> :before-upload="beforeAvatarUpload">
<img v-if="form.upFile != ''" <img v-if="form.upFile != ''"
:src="$store.state.settings.host + '/Data/UploadFiles/temp/' + form.upFile" class="avatar" /> :src="$store.state.settings.host + '/Data/UploadFiles/temp/' + form.upFile" class="avatar" />
<img v-else-if="form.oldFile != '' && form.upFile == ''" <img v-else-if="form.oldFile != [] && form.upFile == ''"
:src="$store.state.settings.host + '/Data/UploadFiles/category/' + form.oldFile" class="avatar" /> :src="form.oldFile[0]" class="avatar" />
<template v-else> <template v-else>
<i class="el-icon-plus f-s-30 m-t-70 seatFontColor"></i> <i class="el-icon-plus f-s-30 m-t-70 seatFontColor"></i>
<div class="el-upload__text"><em>建议40*40像素 <br>svg jpg png gif </em></div> <div class="el-upload__text"><em>建议40*40像素 <br>svg jpg png gif </em></div>
@ -119,7 +119,7 @@ export default {
sort: '', sort: '',
show: false, show: false,
upFile: '', upFile: '',
oldFile: '', oldFile: [],
desc: '' desc: ''
}, },
isStartDel: false, isStartDel: false,
@ -276,7 +276,6 @@ export default {
}, },
categoryList () { categoryList () {
this.categoryListData = this.buildTree(this.categoryList) this.categoryListData = this.buildTree(this.categoryList)
console.log(this.categoryListData)
} }
}, },
created () { created () {

View File

@ -44,8 +44,8 @@
:before-upload="beforeAvatarUpload"> :before-upload="beforeAvatarUpload">
<img v-if="form.upFile != ''" <img v-if="form.upFile != ''"
:src="$store.state.settings.host + '/Data/UploadFiles/temp/' + form.upFile" class="avatar" /> :src="$store.state.settings.host + '/Data/UploadFiles/temp/' + form.upFile" class="avatar" />
<img v-else-if="form.oldFile != '' && form.upFile == ''" <img v-else-if="form.oldFile != [] && form.upFile == ''"
:src="$store.state.settings.host + '/Data/UploadFiles/sku/' + form.oldFile" class="avatar" /> :src="form.oldFile[0]" class="avatar" />
<template v-else> <template v-else>
<i class="el-icon-plus f-s-30 m-t-70 seatFontColor"></i> <i class="el-icon-plus f-s-30 m-t-70 seatFontColor"></i>
<div class="el-upload__text"><em>建议400*400像素 <br> jpg png </em></div> <div class="el-upload__text"><em>建议400*400像素 <br> jpg png </em></div>
@ -94,7 +94,7 @@ export default {
stock: '', stock: '',
purchase_channel: '', purchase_channel: '',
upFile: '', upFile: '',
oldFile: '' oldFile: []
}, },
skuId: this.$route.params.id, // get id skuId: this.$route.params.id, // get id
pageState: 'add', // pageState: 'add', //

View File

@ -29,9 +29,9 @@
<el-table-column prop="unit" label="单位" width="60" min-width="60"> <el-table-column prop="unit" label="单位" width="60" min-width="60">
</el-table-column> </el-table-column>
<el-table-column label="图片" width="120" min-width="120"> <el-table-column label="图片" width="120" min-width="120">
<template v-if="scope.row.photo != ''" slot-scope="scope"> <template v-if="scope.row.photo != []" slot-scope="scope">
<el-image :src="$store.state.settings.host + '/Data/UploadFiles/sku/' + scope.row.photo" <el-image :src="scope.row.photo[0]"
:preview-src-list="[$store.state.settings.host + '/Data/UploadFiles/sku/' + scope.row.photo]"> :preview-src-list="scope.row.photo">
<div slot="error" class="image-slot"> <div slot="error" class="image-slot">
<i class="el-icon-picture-outline"></i> <i class="el-icon-picture-outline"></i>
</div> </div>

View File

@ -56,8 +56,8 @@
:before-upload="beforeAvatarUpload"> :before-upload="beforeAvatarUpload">
<img v-if="form.upFile != ''" <img v-if="form.upFile != ''"
:src="$store.state.settings.host + '/Data/UploadFiles/temp/' + form.upFile" class="avatar" /> :src="$store.state.settings.host + '/Data/UploadFiles/temp/' + form.upFile" class="avatar" />
<img v-else-if="form.oldFile != '' && form.upFile == ''" <img v-else-if="form.oldFile != [] && form.upFile == ''"
:src="$store.state.settings.host + '/Data/UploadFiles/spu/' + form.oldFile" class="avatar" /> :src="form.oldFile[0]" class="avatar" />
<template v-else> <template v-else>
<i class="el-icon-plus f-s-30 m-t-70 seatFontColor"></i> <i class="el-icon-plus f-s-30 m-t-70 seatFontColor"></i>
<div class="el-upload__text"><em>建议288*216像素 <br> jpg png </em></div> <div class="el-upload__text"><em>建议288*216像素 <br> jpg png </em></div>

View File

@ -34,8 +34,8 @@
</el-table-column> </el-table-column>
<el-table-column label="图片" width="120" min-width="120"> <el-table-column label="图片" width="120" min-width="120">
<template v-if="scope.row.photo != ''" slot-scope="scope"> <template v-if="scope.row.photo != ''" slot-scope="scope">
<el-image :src="$store.state.settings.host + '/Data/UploadFiles/spu/' + scope.row.photo" <el-image :src="scope.row.photo[0]"
:preview-src-list="[$store.state.settings.host + '/Data/UploadFiles/spu/' + scope.row.photo]"> :preview-src-list="scope.row.photo">
<div slot="error" class="image-slot"> <div slot="error" class="image-slot">
<i class="el-icon-picture-outline"></i> <i class="el-icon-picture-outline"></i>
</div> </div>