feat:共富商品分类图片上传
This commit is contained in:
1 parent
bf5828ef4d
commit
181f305f91
1 file changed
+22
-3
@@ -53,6 +53,17 @@
|
||||
<view class="my-2">
|
||||
<node-tree v-model="selectedNode" :node-data="categoryTree" />
|
||||
</view>
|
||||
<view class="prefix_title mb-2">分类图</view>
|
||||
<tm-upload-photo
|
||||
v-model="form.picUrl"
|
||||
:maxFileSize="1024 * 1024 * 5"
|
||||
:url="'/api/admin/sys-file/upload'"
|
||||
:header="hooks.useDefaultHeader()"
|
||||
:column="1.6"
|
||||
img-height="360"
|
||||
:max-count="1"
|
||||
/>
|
||||
<view class="sub-text-20 c-red! mb-2">注:图片大小不超过5M</view>
|
||||
<tm-button form-type="submit" block>保 存</tm-button>
|
||||
</tm-form>
|
||||
</view>
|
||||
@@ -66,14 +77,16 @@ import { onLoad } from "@dcloudio/uni-app"
|
||||
import { reactive, ref } from "vue"
|
||||
import NodeTree from "@/sheep/components/node-tree.vue"
|
||||
import { useCategaryManage } from "./use-categary-manage"
|
||||
import { hooks } from "@@/index"
|
||||
import { filePath } from "@/sheep/utils/file"
|
||||
|
||||
const categaryFormDrawer = ref(false)
|
||||
const form = reactive({
|
||||
const form = reactive<any>({
|
||||
id: "",
|
||||
name: "",
|
||||
status: "0", // 状态(0正常,1下架)
|
||||
parentId: "",
|
||||
picUrl: [],
|
||||
})
|
||||
const categoryTree = ref([])
|
||||
const selectedNode = ref<any>({})
|
||||
@@ -98,6 +111,7 @@ const addCategary = () => {
|
||||
name: "",
|
||||
status: "0",
|
||||
parentId: "",
|
||||
picUrl: [],
|
||||
})
|
||||
selectedNode.value = {}
|
||||
categaryFormDrawer.value = true
|
||||
@@ -106,7 +120,8 @@ const addCategary = () => {
|
||||
// 编辑分类
|
||||
const editCategary = (item) => {
|
||||
getCategaryTree()
|
||||
Object.assign(form, item)
|
||||
const picUrl = [{ path: filePath(item.picUrl), response: JSON.stringify({ data: { url: item.picUrl } }) }]
|
||||
Object.assign(form, { ...item, picUrl })
|
||||
selectedNode.value = { id: item.parentId }
|
||||
categaryFormDrawer.value = true
|
||||
}
|
||||
@@ -116,7 +131,11 @@ const saveCategary = async () => {
|
||||
if (!form.name) return uni.showToast({ title: "请填写分类名称", icon: "none" })
|
||||
if (selectedNode.value.id === form.id) return uni.showToast({ title: "父级分类不能是自己", icon: "none" })
|
||||
try {
|
||||
const params = { ...form, parentId: selectedNode.value.id }
|
||||
const params = {
|
||||
...form,
|
||||
parentId: selectedNode.value.id,
|
||||
picUrl: JSON.parse(form.picUrl[0].response).data.url,
|
||||
}
|
||||
uni.showLoading({ title: "保存中..." })
|
||||
const { code, msg } = await (form.id ? prosperityShopApi.editCategary(params) : prosperityShopApi.addCategary(params))
|
||||
if (code != 0) return uni.showToast({ title: msg || "保存失败", icon: "none" })
|
||||
|
||||
Reference in new issue
Block a user