页面
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-08 11:40:28 +08:00
parent 35afeb10e9
commit 539af26541
11 changed files with 141 additions and 143 deletions

View File

@ -3,7 +3,7 @@
"type": "commonjs", "type": "commonjs",
"version": "3.0.0", "version": "3.0.0",
"description": "unibest - 最好的 uniapp 开发模板", "description": "unibest - 最好的 uniapp 开发模板",
"update-time": "2025-08-27", "update-time": "2025-09-08",
"author": { "author": {
"name": "feige996", "name": "feige996",
"zhName": "菲鸽", "zhName": "菲鸽",

View File

@ -2,13 +2,33 @@
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app' import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
import { usePageAuth } from '@/hooks/usePageAuth' import { usePageAuth } from '@/hooks/usePageAuth'
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only' import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
import { useUserStore } from '@/store'
import { getInfoAPI } from '@/service/crmeb/product.ts'
usePageAuth() usePageAuth()
onLaunch(() => { onLaunch(() => {
// main.jsApp.vue
// uni.addInterceptor('switchTab', {
// async invoke(args) {
// console.log('tab', args.url)
// // await useUserStore().getUserInfo
// const res = await getInfoAPI()
// },
// fail(err) {
// console.error(err)
// },
// })
console.log('App Launch') console.log('App Launch')
}) })
onShow(() => { onShow(async () => {
// const res = await getInfoAPI()
// if (!uni.getStorageSync('token')) {
// uni.redirectTo({ url: '/pages/login/login' });
// } else {
// this.fetchData(); //
// }
console.log('App Show') console.log('App Show')
}) })
onHide(() => { onHide(() => {

View File

@ -15,7 +15,7 @@
<view class=""> <view class="">
<view class="background_home"> <view class="background_home">
<view class=""> <view class="">
<view class="" style="" @click="more"> <view class="" style="">
<wd-card custom-class="card-content"> <wd-card custom-class="card-content">
<view class="relative h-50"> <view class="relative h-50">
<wd-img <wd-img
@ -68,7 +68,7 @@
</view> </view>
<scroll-view scroll-x="true" class="scroll-view-container"> <scroll-view scroll-x="true" class="scroll-view-container">
<view class="p-2" style="" @click="more" v-for="item in index_list"> <view class="p-2" style="" v-for="item in index_list">
<wd-card custom-class="card-content"> <wd-card custom-class="card-content">
<view class="content p-2" style="align-items: normal" @click="goPage(item)"> <view class="content p-2" style="align-items: normal" @click="goPage(item)">
<view class="ps-2 flex-content-column"> <view class="ps-2 flex-content-column">
@ -157,15 +157,6 @@ export default defineComponent({
goPage(item) { goPage(item) {
getUrl('/pages/about/detail?id=' + item.id) getUrl('/pages/about/detail?id=' + item.id)
}, },
more(item) {
console.log(item)
if (item.type == 1) {
getUrl(item.url)
} else if (item.type == 2) {
getWebUrl(item.url)
}
},
}, },
}) })
</script> </script>

View File

@ -164,24 +164,26 @@ export default defineComponent({
// }) // })
// url: '/pages/columnGoods/goods_list/index?id=38&title=', // url: '/pages/columnGoods/goods_list/index?id=38&title=',
more(item) { async more(item) {
this.islogin = hasLogin() await hasLogin()
if (this.islogin === false) {
uni.navigateTo({ // this.islogin = hasLogin()
url: '/pages/login/login', // if (this.islogin === false) {
}) // uni.navigateTo({
return // url: '/pages/login/login',
} // })
if (this.islogin === true) { // return
// console.log(item) // }
if (item.type == 1) { // if (this.islogin === true) {
getUrl(item.url) // console.log(item)
} else if (item.type == 2) { if (item.type == 1) {
getWebUrl(item.url) getUrl(item.url)
} else if (item.type == 3) { } else if (item.type == 2) {
getShopWebUrl(item.url) getWebUrl(item.url)
} } else if (item.type == 3) {
getShopWebUrl(item.url)
} }
// }
}, },
}, },
}) })

View File

@ -526,25 +526,16 @@ export default defineComponent({
url: '/pages/about/index?category_id=' + index, url: '/pages/about/index?category_id=' + index,
}) })
}, },
more(item) { async more(item) {
// const islogin = hasLogin() await hasLogin()
const islogin = true if (item.type == 1) {
if (islogin === false) { getUrl(item.url)
uni.navigateTo({ } else if (item.type == 2) {
url: '/pages/login/login', getWebUrl(item.url)
}) } else if (item.type == 3) {
return getShopWebUrl(item.url)
}
if (islogin === true) {
// console.log(item)
if (item.type == 1) {
getUrl(item.url)
} else if (item.type == 2) {
getWebUrl(item.url)
} else if (item.type == 3) {
getShopWebUrl(item.url)
}
} }
// }
}, },
}, },
}) })

View File

@ -21,7 +21,11 @@ onMounted(() => {
}) })
const userStore = useUserStore() const userStore = useUserStore()
function onClose() {
uni.navigateBack({
delta: 1,
})
}
async function decryptPhoneNumber(e) { async function decryptPhoneNumber(e) {
if (!e.detail.iv) { if (!e.detail.iv) {
toast.error('取消登录') toast.error('取消登录')

View File

@ -129,67 +129,15 @@ const userStore = useUserStore()
console.log('userStore', userStore) console.log('userStore', userStore)
import { defineComponent } from 'vue' import { defineComponent } from 'vue'
// export default defineComponent({ async function more(item) {
// data() { await hasLogin()
// return { // console.log(item)
// isLogin: false, if (item.type == 1) {
// userIsLogin: false, getUrl(item.url)
// show: false, } else if (item.type == 2) {
// userStore: {}, getWebUrl(item.url)
// } } else if (item.type == 3) {
// }, getShopWebUrl(item.url)
// onLoad(option) {
// this.userStore = useUserStore()
// this.userIsLogin = useUserStore().userInfo.id ? true : false
// console.log('', this.userIsLogin)
// console.log('', this.userStore.userInfo)
// },
// methods: {
// toLogin() {
// uni.navigateTo({
// url: '/pages/login/login',
// })
// },
// more(item) {
// this.islogin = hasLogin()
// if (this.islogin === false) {
// uni.navigateTo({
// url: '/pages/login/login',
// })
// return
// }
// if (this.islogin === true) {
// // console.log(item)
// if (item.type == 1) {
// getUrl(item.url)
// } else if (item.type == 2) {
// getWebUrl(item.url)
// } else if (item.type == 3) {
// getShopWebUrl(item.url)
// }
// }
// },
// },
// })
function more(item) {
const islogin = hasLogin()
// const islogin = true
if (islogin === false) {
uni.navigateTo({
url: '/pages/login/login',
})
return
}
if (islogin === true) {
// console.log(item)
if (item.type == 1) {
getUrl(item.url)
} else if (item.type == 2) {
getWebUrl(item.url)
} else if (item.type == 3) {
getShopWebUrl(item.url)
}
} }
} }
const show = ref(false) const show = ref(false)

View File

@ -22,8 +22,12 @@ const formData = reactive({
user_id: '', user_id: '',
}) })
const address = ref('')
function getUserInfo() { function getUserInfo() {
userInfoApi().then((res) => { userInfoApi().then((res) => {
address.value = '审核通过后商品会自动上架到(' + res.data.village_name + ')'
if (res.data.group_id == 2) { if (res.data.group_id == 2) {
isManager.value = true isManager.value = true
userListApi({ code: res.data.village }).then((res) => { userListApi({ code: res.data.village }).then((res) => {
@ -147,6 +151,9 @@ getUserInfo()
@success="uploadSuccess" @success="uploadSuccess"
/> />
</view> </view>
<view>
<wd-notice-bar :text="address" wrapable :scrollable="false" prefix="warn-bold" />
</view>
</wd-cell-group> </wd-cell-group>
</wd-form> </wd-form>
</view> </view>

View File

@ -59,6 +59,11 @@ export const useUserStore = defineStore(
const getUserInfo = async () => { const getUserInfo = async () => {
const res = await _getUserInfo() const res = await _getUserInfo()
const user = res.data const user = res.data
if (res.code === 401) {
toast.error('登录已过期,请重新登录')
_logout()
removeUserInfo()
}
const newData = userInfo.value const newData = userInfo.value
newData.isset = !!user.village newData.isset = !!user.village
newData.avatar = user.avatar newData.avatar = user.avatar

View File

@ -1,5 +1,5 @@
import type { CustomRequestOptions } from '@/interceptors/request' import type { CustomRequestOptions } from '@/interceptors/request'
import { useUserStore } from '@/store'
export function http<T>(options: CustomRequestOptions) { export function http<T>(options: CustomRequestOptions) {
// 1. 返回 Promise 对象 // 1. 返回 Promise 对象
return new Promise<IResData<T>>((resolve, reject) => { return new Promise<IResData<T>>((resolve, reject) => {
@ -10,14 +10,15 @@ export function http<T>(options: CustomRequestOptions) {
responseType: 'json', responseType: 'json',
// #endif // #endif
// 响应成功 // 响应成功
success(res) { async success(res) {
// 状态码 2xx参考 axios 的设计 // 状态码 2xx参考 axios 的设计
if (res.statusCode >= 200 && res.statusCode < 300) { if (res.statusCode >= 200 && res.statusCode < 300) {
// 2.1 提取核心数据 res.data // 2.1 提取核心数据 res.data
resolve(res.data as IResData<T>) resolve(res.data as IResData<T>)
} else if (res.statusCode === 401) { } else if (res.statusCode === 401) {
// 401错误 -> 清理用户信息,跳转到登录页 // 401错误 -> 清理用户信息,跳转到登录页
// userStore.clearUserInfo() const userStore = useUserStore()
await userStore.logout()
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
title: (res.data as IResData<T>).msg || '请登录', title: (res.data as IResData<T>).msg || '请登录',

View File

@ -1,6 +1,7 @@
import { pages, subPackages } from '@/pages.json' import { pages, subPackages } from '@/pages.json'
import { isMpWeixin } from './platform' import { isMpWeixin } from './platform'
import { getInfoAPI } from '@/service/crmeb/product.ts'
import { http } from '@/utils/http'
export function getLastPage() { export function getLastPage() {
// getCurrentPages() 至少有1个元素所以不再额外判断 // getCurrentPages() 至少有1个元素所以不再额外判断
// const lastPage = getCurrentPages().at(-1) // const lastPage = getCurrentPages().at(-1)
@ -219,33 +220,61 @@ export function getShopWebUrl(url) {
import { useUserStore } from '@/store' import { useUserStore } from '@/store'
// const userStore = useUserStore() // const userStore = useUserStore()
// 代登录跳转 // 代登录跳转
export function hasLogin() { export async function hasLogin() {
const hasLogin = useUserStore().userInfo.id ? true : false const res = await getInfoAPI()
// console.log(useUserStore().userInfo) // const res = await http.get('/api/user/info', {})
// console.log('是否登录', hasLogin) console.log('hasLogin', res)
// console.log('是否登录sss', useUserStore().userInfo) if (res.code === 401) {
//强制跳转设置村庄 const hasLogin = false
if (hasLogin && !useUserStore().userInfo.isset) { //强制跳转设置村庄
// if (!this.phone) { if (hasLogin && !useUserStore().userInfo.isset) {
// uni.showToast({ // if (!this.phone) {
// title: '请填写手机号', // uni.showToast({
// icon: 'none', // title: '请填写手机号',
// }) // icon: 'none',
// return // })
// } // return
uni.showModal({ // }
title: '温馨提示', uni.showModal({
content: ' 您尚未完善个人信息,是否前往设置你的个人地址?', title: '温馨提示',
success: function (res) { content: ' 您尚未完善个人信息,是否前往设置你的个人地址?',
if (res.confirm) { success: function (res) {
uni.navigateTo({ if (res.confirm) {
url: '/pages/my/setting?type=1', uni.navigateTo({
}) url: '/pages/my/setting?type=1',
} })
}, }
}) },
return })
return
}
//返回是否登录
return hasLogin
} else {
const hasLogin = true
//强制跳转设置村庄
if (hasLogin && !useUserStore().userInfo.isset) {
// if (!this.phone) {
// uni.showToast({
// title: '请填写手机号',
// icon: 'none',
// })
// return
// }
uni.showModal({
title: '温馨提示',
content: ' 您尚未完善个人信息,是否前往设置你的个人地址?',
success: function (res) {
if (res.confirm) {
uni.navigateTo({
url: '/pages/my/setting?type=1',
})
}
},
})
return
}
//返回是否登录
return hasLogin
} }
//返回是否登录
return hasLogin
} }