对接接口

This commit is contained in:
wangxiaowei
2025-12-17 23:34:08 +08:00
parent 018a784a8c
commit df863a2f41
19 changed files with 792 additions and 389 deletions

View File

@ -24,7 +24,7 @@
<view class="mt-32rpx">
<view class="font-bold text-32rpx text-[#303133] leading-44rpx">抖音UID</view>
<view class="mt-10rpx">
<wd-input v-model="form.uid" :maxlength="20" show-word-limit placeholder="请输入抖音UID"/>
<wd-input v-model="form.dy_uid" :maxlength="20" show-word-limit placeholder="请输入抖音UID"/>
</view>
</view>
@ -34,11 +34,11 @@
<view class="mt-50rpx">
<view class="text-30rpx leading-42rpx text-[#303133]">省市区</view>
<view class="border-b border-b-solid border-b-[#e5e7eb] area">
<wd-col-picker v-model="form.area" :columns="area" :column-change="columnChange" @confirm="EditStore.handleConfirmAddress" placeholder="请选择省市区"></wd-col-picker>
<wd-col-picker v-model="address" :columns="area" :column-change="columnChange" auto-complete @confirm="EditStore.handleConfirmAddress" placeholder="请选择省市区"> </wd-col-picker>
</view>
</view>
<view class="mt-28rpx">
<view class="text-30rpx leading-42rpx text-[#303133]">省市区</view>
<view class="text-30rpx leading-42rpx text-[#303133]">地址</view>
<view>
<wd-input v-model="form.address" placeholder="请填写具体地址"/>
</view>
@ -66,12 +66,12 @@
<view class="mt-32rpx">
<view class="font-bold text-32rpx text-[#303133] leading-44rpx">门店电话</view>
<view class="mt-10rpx">
<wd-input v-model="form.uid" :maxlength="20" show-word-limit placeholder="请输入门店电话"/>
<wd-input v-model="form.contact_phone" :maxlength="20" show-word-limit placeholder="请输入门店电话"/>
</view>
</view>
<!-- 门店视频 -->
<view class="mt-32rpx">
<!-- <view class="mt-32rpx">
<view class="font-bold text-32rpx text-[#303133] leading-44rpx">门店视频</view>
<view class="mt-32rpx">
<wd-upload :file-list="fileList" :limit="1" image-mode="scaleToFill" accept="video" :action="action"
@ -86,14 +86,13 @@
</view>
</wd-upload>
</view>
</view>
</view> -->
<!-- 门店图片 -->
<view class="mt-32rpx">
<view class="font-bold text-32rpx text-[#303133] leading-44rpx">门店图片</view>
<view class="mt-32rpx">
<wd-upload :file-list="fileList" :limit="9" image-mode="scaleToFill" accept="image" :action="action"
@change="EditStore.handleUploadFile">
<wd-upload :header="{'token': token}" :file-list="fileList" image-mode="aspectFill" :limit="9" multiple :action="action"
@change="EditStore.handleUploadFile">
<view
class="border-2rpx border-dashed border-[#E5E5E5] w-184rpx h-184rpx flex flex-col items-center justify-center rounded-16rpx">
<view class="">
@ -116,37 +115,26 @@
<script lang="ts" setup>
import { useColPickerData } from '@/hooks/useColPickerData'
import { toast } from '@/utils/toast'
import { getStoreDetails, editStoreInfo } from '@/api/store'
import { useStoreStore } from '@/store'
const OSS = inject('OSS')
const useStore = useStoreStore()
const token = ref<string>('') // 用户token
// 上传文件
// const fileList = ref<any[]>([])
const fileList = ref<any[]>([])
const action = 'https://www.mocky.io/v2/5cc8019d300000980a055e76' // 仅做测试使用,实际请换成真实上传接口
// 表单数据
const form = ref({
name: "",
uid: "",
area: [],
address: "",
start_time: "",
end_time: "",
phone: ""
})
const action = import.meta.env.VITE_UPLOAD_BASEURL
// 省市区数据
const { colPickerData, findChildrenByCode } = useColPickerData()
const value = ref<string[]>([])
const area = ref<any[]>([
colPickerData.map((item) => {
return {
value: item.value,
label: item.text
}
})
])
const columnChange = ({ selectedItem, resolve, finish }) => {
const areaData = findChildrenByCode(colPickerData, selectedItem.value)
const address = ref<string[]>([])
const area = ref<any[]>([])
const columnChange = async ({ selectedItem, resolve, finish }) => {
await EditStore.handleSleep(0)
const areaData = findChildrenByCode(colPickerData, selectedItem.value)
if (areaData && areaData.length) {
resolve(
areaData.map((item) => {
@ -161,27 +149,178 @@
}
}
// 门店信息
const form = ref({
id: 0,
name: '',
dy_uid: '',
image: '',
image_arr: [],
video: '',
province: '',
province_id: 0,
city: '',
city_id: 0,
district: '',
district_id: 0,
address: '',
area: '',
contact_phone: '',
day_time: '',
start_time: '',
end_time: '',
})
onShow(() => {
})
onLoad(() => {
token.value = uni.getStorageSync('token')
EditStore.handleGetStoreDetails()
})
const EditStore = {
fileList: [],
/**
* 获取店铺详情
*/
handleGetStoreDetails: async () => {
const storeDetails = await getStoreDetails(useStore.defaultStore.id)
// 只取需要的字段赋值,避免污染
const d = storeDetails.details
form.value = {
id: d.id,
name: d.name,
dy_uid: d.dy_uid,
image: d.image,
image_arr: d.image_arr || [],
video: d.video || '',
province: d.province,
province_id: d.province_id,
city: d.city,
city_id: d.city_id,
district: d.district,
district_id: d.district_id,
address: d.address,
area: d.area,
contact_phone: d.contact_phone,
day_time: d.day_time,
start_time: d.start_time,
end_time: d.end_time,
}
fileList.value = (d.image_arr || []).map((item: string) => ({ url: item, name: item}))
EditStore.fileList = fileList.value
address.value = [
String(d.province_id),
String(d.city_id),
String(d.district_id)
]
},
/**
* 选择省市区
* @param selected
*/
handleConfirmAddress(selected) {
form.value.address = selected.map(item => item.label)
handleConfirmAddress(item) {
form.value.province = item.selectedItems[0].label
form.value.province_id = Number(item.selectedItems[0].value)
form.value.city = item.selectedItems[1].label
form.value.city_id = Number(item.selectedItems[1].value)
form.value.district = item.selectedItems[2].label
form.value.district_id = Number(item.selectedItems[2].value)
},
/**
* 图片选择/删除
*/
handleUploadFile: (event: any) => {
fileList.value = event.fileList
handleUploadFile: ({ fileList: files }) => {
let url = ''
let name = ''
let response = null
const res = files.map(item => {
if (item.response) {
response = JSON.parse(item.response)
url = response.data.uri
name = response.data.name
}
return {
name: name || item.name,
url: url || item.url
}
})
EditStore.fileList = res
},
/**
* 保存门店信息
*/
handleSaveStoreInfo: () => {
toast.info('保存成功')
handleSaveStoreInfo: async () => {
if (!form.value.name) {
toast.info('请输入门店名称')
return
}
if (!form.value.address) {
toast.info('请输入门店地址')
return
}
if (!form.value.start_time) {
toast.info('请选择营业开始时间')
return
}
if (!form.value.end_time) {
toast.info('请选择营业结束时间')
return
}
if (!form.value.contact_phone) {
toast.info('请输入门店电话')
return
}
if (EditStore.fileList.length === 0) {
toast.info('请上传门店图片')
return
}
form.value.image_arr = EditStore.fileList.map(item => item.url)
form.value.image = EditStore.fileList[0].url
form.value.id = useStore.defaultStore.id
uni.showLoading({
title: '保存中...'
})
try {
await editStoreInfo(form.value)
EditStore.handleGetStoreDetails()
uni.hideLoading()
toast.info('保存成功')
} catch (error) {
uni.hideLoading()
toast.info('保存失败,请稍后重试')
return
}
},
/**
* 等待城市数据渲染
* @param second
*/
handleSleep: async (second: number = 1) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true)
}, 1000 * second)
})
}
}