页面提交
Some checks are pending
Auto Merge Main to Other Branches / Merge main into i18n (push) Waiting to run
Auto Merge Main to Other Branches / Merge main into base-sard-ui (push) Waiting to run

This commit is contained in:
sjeam 2025-09-02 16:55:04 +08:00
parent 78c6170ef0
commit 649470558e
9 changed files with 263 additions and 214 deletions

View File

@ -94,6 +94,7 @@
"@dcloudio/uni-mp-xhs": "3.0.0-4060620250520001",
"@dcloudio/uni-quickapp-webview": "3.0.0-4060620250520001",
"@tanstack/vue-query": "^5.62.16",
"@vant/area-data": "^2.1.0",
"abortcontroller-polyfill": "^1.7.8",
"dayjs": "1.11.10",
"js-cookie": "^3.0.5",

8
pnpm-lock.yaml generated
View File

@ -70,6 +70,9 @@ importers:
'@tanstack/vue-query':
specifier: ^5.62.16
version: 5.62.16(vue@3.5.15(typescript@5.7.2))
'@vant/area-data':
specifier: ^2.1.0
version: 2.1.0
abortcontroller-polyfill:
specifier: ^1.7.8
version: 1.7.8
@ -2502,6 +2505,9 @@ packages:
peerDependencies:
vite: ^2.9.0 || ^3.0.0-0 || ^4.0.0 || ^5.0.0-0 || ^6.0.0-0
'@vant/area-data@2.1.0':
resolution: {integrity: sha512-wx9PrUX7wSUJiFcz8UrcvZfTjV6sTc+7SHcbjGQQzEcv5y+EwOo5uV4ZKdfrR5Hzcw4MA08LQdvXPSEb4nWbug==}
'@vitejs/plugin-legacy@5.3.2':
resolution: {integrity: sha512-8moCOrIMaZ/Rjln0Q6GsH6s8fAt1JOI3k8nmfX4tXUxE5KAExVctSyOBk+A25GClsdSWqIk2yaUthH3KJ2X4tg==}
engines: {node: ^18.0.0 || >=20.0.0}
@ -9678,6 +9684,8 @@ snapshots:
- vue
optional: true
'@vant/area-data@2.1.0': {}
'@vitejs/plugin-legacy@5.3.2(terser@5.36.0)(vite@5.2.8(@types/node@20.17.9)(sass@1.77.8)(terser@5.36.0))':
dependencies:
'@babel/core': 7.26.0

View File

@ -37,14 +37,14 @@ export function login(loginForm: ILoginForm) {
*
*/
export function getUserInfo() {
return http.get<IUserInfoVo>('/user/info')
return http.get('/api/user/info')
}
/**
* 退
*/
export function logout() {
return http.get<void>('/user/logout')
return http.get<void>('/api/user/logout')
}
/**

View File

@ -0,0 +1,38 @@
// 可以将此代码放置于项目src/hooks/useColPickerData.ts中
import { useCascaderAreaData } from '@vant/area-data'
export type CascaderOption = {
text: string
value: string
children?: CascaderOption[]
}
/**
* 使'@vant/area-data'ColPicker组件的数据
* @returns
*/
export default function useColPickerData() {
// '@vant/area-data' 数据源
const colPickerData: CascaderOption[] = useCascaderAreaData()
// 根据code查找子节点不传code则返回所有节点
function findChildrenByCode(data: CascaderOption[], code?: string): CascaderOption[] | null {
if (!code) {
return data
}
for (const item of data) {
if (item.value === code) {
return item.children || null
}
if (item.children) {
const childrenResult = findChildrenByCode(item.children, code)
if (childrenResult) {
return childrenResult
}
}
}
return null
}
return { colPickerData, findChildrenByCode }
}

3
src/hooks/index.ts Normal file
View File

@ -0,0 +1,3 @@
import useColPickerData from './area-data'
export { useColPickerData }

View File

@ -80,9 +80,11 @@ const httpInterceptor = {
// 3. 添加 token 请求头标识
const userStore = useUserStore()
const { token } = userStore.userInfo as unknown as IUserInfo
if (token) {
options.header.Authorization = `Bearer ${token}`
}
// console.log('token', token)
// if (token) {
// options.header.Authorization = `Bearer ${token.access_token}`
// }
options.header.Authorization = `Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3ZWJtYW4udGlueXdhbi5jbiIsImF1ZCI6IndlYm1hbi50aW55d2FuLmNuIiwiaWF0IjoxNzU2ODAyMTM3LCJuYmYiOjE3NTY4MDIxMzcsImV4cCI6MTc1NjgwOTMzNywiZXh0ZW5kIjp7ImlkIjoyMX19.3Zp61BOC34ZC919a2ifNUoZJb2RAYZxNjH7j_Enj1P0`
},
}

View File

@ -35,7 +35,7 @@
</view>
</wd-grid>
</wd-card>
<!-- <button v-if="hasLogin" class="mt-2" @click="logout">退出登录</button> -->
<button v-if="hasLogin" class="mt-2" @click="logout">退出登录</button>
</view>
</view>
</template>
@ -44,10 +44,9 @@
import { useUserStore } from '@/store'
import { http } from '@/utils/http'
import WxLogin from './components/wx-login.vue'
const userStore = useUserStore()
const hasLogin = computed(() => userStore.userInfo?.nickname)
const userStore = useUserStore()
const openId = ref('')
const logout = () => {

View File

@ -4,33 +4,70 @@
}
</route>
<template>
<view>
<wx-login />
<!-- <view class="ml-4">wx的openid:</view> -->
<!-- <view class="ml-4">{{ openId }}</view> -->
<view class="p-2">
<view class="p-2 detail-box bg-white">
<wd-card>
<wd-cell-group>
<!-- <wd-cell title="标题文字" center>
<wd-button custom-class="custom-value" size="small" plain>按钮</wd-button>
</wd-cell>
<wd-cell title="标题文字" center>
<view class="custom-value" style="height: 32px">
<wd-switch v-model="switchValue" change="handleSwitchChange" />
</view>
</wd-cell> -->
<wd-cell title="我的钱包" is-link to="/pages/index/index">
<wd-cell
icon=""
title="昵称"
right-icon="lock"
:value="userInfo.nickname"
:border="false"
size="large"
custom-style="padding:20rpx;font-size:28rpx"
/>
<wd-cell
icon=""
title="角色"
right-icon="lock"
:value="userInfo.group_name"
:border="false"
size="large"
custom-style="padding:20rpx;font-size:28rpx"
/>
<wd-cell
icon=""
title="手机号"
is-link
right-icon="lock"
:value="userInfo.phone"
:border="false"
size="large"
custom-style="padding:20rpx;font-size:28rpx"
/>
<wd-cell
icon="order"
title="我的订单"
is-link
value=""
:border="false"
size="large"
custom-style="padding:20rpx;font-size:28rpx"
@click="myOrder"
/>
<wd-cell
title="我的钱包"
is-link
to="/pages/index/index"
:border="false"
size="large"
custom-style="padding:20rpx;font-size:28rpx"
>
<view class="custom-text"></view>
</wd-cell>
<wd-col-picker
label="做宴地址"
v-model="orderInfo.district_name"
prop="district_name"
v-model="address"
prop="address"
:columns="area"
:column-change="columnChange"
placeholder="请填写做宴地址"
@confirm="handleConfirm"
:border="false"
size="large"
custom-style="padding:20rpx;font-size:28rpx"
:rules="[
{
required: false,
@ -44,82 +81,40 @@
},
]"
></wd-col-picker>
<!-- <wd-cell>
<template #title>
<view>
<view style="display: inline-block">标题文字</view>
<view class="end-time">25天后到期</view>
</view>
</template>
</wd-cell> -->
</wd-cell-group>
</wd-card>
</view>
<button v-if="hasLogin" class="mt-2" @click="logout">退出登录</button>
</view>
</view>
</template>
<style>
.cell-icon {
display: block;
box-sizing: border-box;
padding: 4px 0;
width: 16px;
height: 24px;
margin-right: 4px;
background: url('https://img10.360buyimg.com/jmadvertisement/jfs/t1/71075/7/3762/1820/5d1f26d1E0d600b9e/a264c901943080ac.png')
no-repeat;
background-size: cover;
}
:deep(.custom-value) {
position: absolute;
top: 50%;
right: 0;
transform: translate(0, -50%);
white-space: nowrap;
}
.custom-text {
color: #f0883a;
}
.end-time {
display: inline-block;
margin-left: 8px;
border: 1px solid #faa21e;
padding: 0 4px;
font-size: 10px;
color: #faa21e;
}
</style>
<script lang="ts">
const switchValue = ref('')
function handleSwitchChange({ value }) {
console.log(value)
}
// import { useUserStore } from '@/store'
// import { http } from '@/utils/http'
// import WxLogin from './components/wx-login.vue'
import { useUserStore } from '@/store'
const userStore = useUserStore()
const hasLogin = computed(() => userStore.userInfo?.nickname)
// const userStore = useUserStore()
// const openId = ref('')
// const logout = () => {
// uni.showModal({
// title: '退',
// success: (res) => {
// if (res.confirm) {
// userStore.logout()
// }
// },
// })
// }
import { useColPickerData, useModal } from '@/hooks'
const { colPickerData, findChildrenByCode } = useColPickerData()
import { defineComponent } from 'vue'
import {
getInfoAPI,
getCityAPI,
getDistrictAPI,
getStreetAPI,
getVillageAPI,
} from '@/service/crmeb/product.ts'
export default defineComponent({
data() {
return {
hasLogin: false,
totalPrice: 0,
pre_price: 0,
server_user: {
@ -134,37 +129,63 @@ export default defineComponent({
area: [],
value: [],
order_type: 1, // 2
orderInfo: {
district_name: [],
street_name: '',
cart_ids: 0, //
customer_name: '',
userInfo: {
nickname: '',
phone: '',
address: '',
remark: '',
banquet_type: '1',
reservation_type: 1,
server_user_id: 0,
table_number: 1, //
banquet_date: null, //
group_name: '',
district_name: [],
},
matchedItems_sp: [],
address: [],
// district: 0, //
// street: 0, //
// village: 0, //
showDatePicker: false,
}
},
onLoad(option) {
this.server_user_id = option.id
this.orderInfo.cart_ids = option.cart_ids || 0
if (this.orderInfo.cart_ids) {
this.order_type = 2 //
}
this.orderInfo.server_user_id = option.id
this.getCartCheck()
async onLoad(option) {
this.getArea()
this.getUserInfo()
},
methods: {
logout() {
uni.showModal({
title: '确认退出当前账号?',
success: (res) => {
if (res.confirm) {
userStore.logout()
this.goBack()
}
},
})
},
async getDistrict() {
const res = await getDistrictAPI()
if (res.code === 1) {
const areaData = res.data
this.area = [
areaData.map((item) => ({
value: item.code,
label: item.name,
grade: 1,
})),
]
}
},
async getUserInfo() {
this.hasLogin = userStore.userInfo?.nickname
const res = await getInfoAPI()
if (res.code === 1) {
console.log('用户信息:', res.data)
this.userInfo = res.data
}
},
pickDate(e) {
this.orderInfo.banquet_date = e[0]
// this.userInfo.banquet_date = e[0]
this.showDatePicker = false
},
close() {
@ -172,12 +193,12 @@ export default defineComponent({
},
//
handleSubmit(reservation_type) {
this.orderInfo.reservation_type = reservation_type //
this.userInfo.reservation_type = reservation_type //
this.$refs.form
.validate()
.then(({ valid, errors }) => {
if (valid) {
this.orderInfo.address = this.address_string + this.orderInfo.street_name
this.userInfo.address = this.address_string + this.userInfo.street_name
this.addOrder()
}
})
@ -186,118 +207,64 @@ export default defineComponent({
})
},
// //
// addOrder() {
// CommonApi.commonPost('/api/banquet/order/createOrder', this.orderInfo).catch((res) => {
// if (res.code === 1) {
// this.order_id = res.data.order_id
// uni.navigateTo({
// url: `/pages/banquet/order/detail?order_id=${res.data.order_id}`,
// })
// } else if (res.code === 0) {
// uni.$u.toast('')
// this.goBack()
// } else {
// uni.$u.toast(res.msg)
// }
// })
// },
// //
// payOrder() {
// CommonApi.commonPost('/api/banquet/order/pay', {
// order_id: this.order_id,
// }).catch((res) => {
// if (res.code === 1) {
// wx.requestPayment({
// timeStamp: res.data.timeStamp,
// nonceStr: res.data.nonceStr,
// package: res.data.package,
// signType: res.data.signType,
// paySign: res.data.paySign,
// success: function (res) {
// console.log('success:' + JSON.stringify(res))
// },
// fail: function (err) {
// console.log('fail:' + JSON.stringify(err))
// },
// complete: function (res) {
// console.log('complete:' + JSON.stringify(res))
// },
// })
// } else {
// uni.$u.toast(res.msg)
// }
// })
// },
//
//--
getArea() {
this.area = [
colPickerData.map((item) => ({
value: item.value,
label: item.text,
})),
]
this.getDistrict()
},
//--
handleConfirm(value) {
// console.log(value.value.length)
this.addressNumber = value.value.length
this.address_string = value.selectedItems.map((item) => item.label).join('')
},
//
columnChange({ selectedItem, resolve, finish }) {
async columnChange({ selectedItem, resolve, finish }) {
try {
const areaData = findChildrenByCode(colPickerData, selectedItem.value)
if (selectedItem.grade === 1) {
//
const res = await getStreetAPI(selectedItem.value)
if (res.code === 1) {
const areaData = res.data
if (areaData && areaData.length) {
resolve(
areaData.map((item) => ({
value: item.value,
label: item.text,
value: item.code,
label: item.name,
grade: 2,
})),
)
} else {
finish()
}
}
return
}
if (selectedItem.grade === 2) {
//
const res = await getVillageAPI(selectedItem.value)
if (res.code === 1) {
const areaData = res.data
if (areaData && areaData.length) {
resolve(
areaData.map((item) => ({
value: item.code,
label: item.name,
grade: 3,
})),
)
} else {
finish()
}
}
} else {
finish()
}
} catch (error) {
console.error('处理列变更时出错:', error)
finish() //
}
},
// //
// getBanquetType() {
// CommonApi.commonGet('/api/banquet/dishes/banquetType').catch((res) => {
// if (res.code === 1) {
// res.data.forEach((item) => {
// item.label = item.name
// })
// this.banquetType = res.data
// } else {
// uni.$u.toast(res.msg)
// }
// })
// },
// //
getCartCheck() {
let query = {
server_user_id: this.server_user_id,
cart_ids: 0,
}
if (this.order_type == 2 && this.orderInfo.cart_ids > 0) {
query.cart_ids = this.orderInfo.cart_ids
}
// CommonApi.commonPost('/api/banquet/order/check', query).catch((res) => {
// if (res.code === 1) {
// this.matchedItems_sp = res.data.cart_list
// this.totalPrice = res.data.total_price
// this.pre_price = this.totalPrice >= 1000 ? 1000 : this.totalPrice
// this.server_user.phone = res.data.server_user.certification.phone
// this.server_user.public_name = res.data.server_user.certification.public_name
// this.$refs.pagingRefSP?.complete(res.data)
// // console.log(res);
// } else {
// uni.$u.toast(res.msg)
// }
// })
},
myOrder() {},
//
goBack() {

View File

@ -5,25 +5,56 @@ export interface IFooItem {
// name: string
// any: any
}
// /** GET 请求;支持 传递 header 的范例 */
// export function getFooAPI2(name: string) {
// return http.get<IFooItem>('/foo', { name }, { 'Content-Type-100': '100' })
// }
// /** POST 请求 */
// export function postFooAPI(name: string) {
// return http.post<IFooItem>('/foo', { name })
// }
// /** POST 请求;需要传递 query 参数的范例微信小程序经常有同时需要query参数和body参数的场景 */
// export function postFooAPI2(name: string) {
// return http.post<IFooItem>('/foo', { name })
// }
// /** POST 请求;支持 传递 header 的范例 */
// export function postFooAPI3(name: string) {
// return http.post<IFooItem>('/foo', { name }, { name }, { 'Content-Type-100': '100' })
// }
/** GET 请求 */
export function getProductAPI(cate_pid: string) {
return http.get<IFooItem>(getUrlCrmebProxy() + '/api/product/spu/lst', { cate_pid })
}
/** GET 请求;支持 传递 header 的范例 */
export function getFooAPI2(name: string) {
return http.get<IFooItem>('/foo', { name }, { 'Content-Type-100': '100' })
export function getInfoAPI() {
return http.post('/api/user/info', {})
}
/** POST 请求 */
export function postFooAPI(name: string) {
return http.post<IFooItem>('/foo', { name })
export function setInfoPI() {
return http.get('/api/user/setInfo', {})
}
/** POST 请求;需要传递 query 参数的范例微信小程序经常有同时需要query参数和body参数的场景 */
export function postFooAPI2(name: string) {
return http.post<IFooItem>('/foo', { name })
export function setPhoneAPI() {
return http.get('/api/user/setPhone', {})
}
/** POST 请求;支持 传递 header 的范例 */
export function postFooAPI3(name: string) {
return http.post<IFooItem>('/foo', { name }, { name }, { 'Content-Type-100': '100' })
export function setGroupAPI() {
return http.get('/api/user/setGroup', {})
}
export function getCityAPI() {
return http.get('/api/location/getCity', {})
}
export function getDistrictAPI() {
return http.get('/api/location/getDistrict', {})
}
export function getStreetAPI(code: string) {
return http.get('/api/location/getStreet', { code })
}
export function getVillageAPI(code: string) {
return http.get('/api/location/getVillage', { code })
}