页面
This commit is contained in:
parent
35afeb10e9
commit
539af26541
@ -3,7 +3,7 @@
|
||||
"type": "commonjs",
|
||||
"version": "3.0.0",
|
||||
"description": "unibest - 最好的 uniapp 开发模板",
|
||||
"update-time": "2025-08-27",
|
||||
"update-time": "2025-09-08",
|
||||
"author": {
|
||||
"name": "feige996",
|
||||
"zhName": "菲鸽",
|
||||
|
24
src/App.vue
24
src/App.vue
@ -2,13 +2,33 @@
|
||||
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
|
||||
import { usePageAuth } from '@/hooks/usePageAuth'
|
||||
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
|
||||
|
||||
import { useUserStore } from '@/store'
|
||||
import { getInfoAPI } from '@/service/crmeb/product.ts'
|
||||
usePageAuth()
|
||||
|
||||
onLaunch(() => {
|
||||
// 在main.js或App.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')
|
||||
})
|
||||
onShow(() => {
|
||||
onShow(async () => {
|
||||
// const res = await getInfoAPI()
|
||||
// if (!uni.getStorageSync('token')) {
|
||||
// uni.redirectTo({ url: '/pages/login/login' });
|
||||
// } else {
|
||||
// this.fetchData(); // 发起请求
|
||||
// }
|
||||
|
||||
console.log('App Show')
|
||||
})
|
||||
onHide(() => {
|
||||
|
@ -15,7 +15,7 @@
|
||||
<view class="">
|
||||
<view class="background_home">
|
||||
<view class="">
|
||||
<view class="" style="" @click="more">
|
||||
<view class="" style="">
|
||||
<wd-card custom-class="card-content">
|
||||
<view class="relative h-50">
|
||||
<wd-img
|
||||
@ -68,7 +68,7 @@
|
||||
</view>
|
||||
|
||||
<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">
|
||||
<view class="content p-2" style="align-items: normal" @click="goPage(item)">
|
||||
<view class="ps-2 flex-content-column">
|
||||
@ -157,15 +157,6 @@ export default defineComponent({
|
||||
goPage(item) {
|
||||
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>
|
||||
|
@ -164,15 +164,17 @@ export default defineComponent({
|
||||
// })
|
||||
|
||||
// url: '/pages/columnGoods/goods_list/index?id=38&title=名优特产',
|
||||
more(item) {
|
||||
this.islogin = hasLogin()
|
||||
if (this.islogin === false) {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login',
|
||||
})
|
||||
return
|
||||
}
|
||||
if (this.islogin === true) {
|
||||
async more(item) {
|
||||
await hasLogin()
|
||||
|
||||
// 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)
|
||||
@ -181,7 +183,7 @@ export default defineComponent({
|
||||
} else if (item.type == 3) {
|
||||
getShopWebUrl(item.url)
|
||||
}
|
||||
}
|
||||
// }
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -526,17 +526,8 @@ export default defineComponent({
|
||||
url: '/pages/about/index?category_id=' + index,
|
||||
})
|
||||
},
|
||||
more(item) {
|
||||
// const islogin = hasLogin()
|
||||
const islogin = true
|
||||
if (islogin === false) {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login',
|
||||
})
|
||||
return
|
||||
}
|
||||
if (islogin === true) {
|
||||
// console.log(item)
|
||||
async more(item) {
|
||||
await hasLogin()
|
||||
if (item.type == 1) {
|
||||
getUrl(item.url)
|
||||
} else if (item.type == 2) {
|
||||
@ -544,7 +535,7 @@ export default defineComponent({
|
||||
} else if (item.type == 3) {
|
||||
getShopWebUrl(item.url)
|
||||
}
|
||||
}
|
||||
// }
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -21,7 +21,11 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
function onClose() {
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
})
|
||||
}
|
||||
async function decryptPhoneNumber(e) {
|
||||
if (!e.detail.iv) {
|
||||
toast.error('取消登录')
|
||||
|
@ -129,59 +129,8 @@ const userStore = useUserStore()
|
||||
console.log('userStore', userStore)
|
||||
import { defineComponent } from 'vue'
|
||||
|
||||
// export default defineComponent({
|
||||
// data() {
|
||||
// return {
|
||||
// isLogin: false,
|
||||
// userIsLogin: false,
|
||||
// show: false,
|
||||
// userStore: {},
|
||||
// }
|
||||
// },
|
||||
// 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) {
|
||||
async function more(item) {
|
||||
await hasLogin()
|
||||
// console.log(item)
|
||||
if (item.type == 1) {
|
||||
getUrl(item.url)
|
||||
@ -191,7 +140,6 @@ function more(item) {
|
||||
getShopWebUrl(item.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
const show = ref(false)
|
||||
|
||||
function toLogin() {
|
||||
|
@ -22,8 +22,12 @@ const formData = reactive({
|
||||
user_id: '',
|
||||
})
|
||||
|
||||
const address = ref('')
|
||||
|
||||
function getUserInfo() {
|
||||
userInfoApi().then((res) => {
|
||||
address.value = '审核通过后商品会自动上架到(' + res.data.village_name + ')'
|
||||
|
||||
if (res.data.group_id == 2) {
|
||||
isManager.value = true
|
||||
userListApi({ code: res.data.village }).then((res) => {
|
||||
@ -147,6 +151,9 @@ getUserInfo()
|
||||
@success="uploadSuccess"
|
||||
/>
|
||||
</view>
|
||||
<view>
|
||||
<wd-notice-bar :text="address" wrapable :scrollable="false" prefix="warn-bold" />
|
||||
</view>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
@ -59,6 +59,11 @@ export const useUserStore = defineStore(
|
||||
const getUserInfo = async () => {
|
||||
const res = await _getUserInfo()
|
||||
const user = res.data
|
||||
if (res.code === 401) {
|
||||
toast.error('登录已过期,请重新登录')
|
||||
_logout()
|
||||
removeUserInfo()
|
||||
}
|
||||
const newData = userInfo.value
|
||||
newData.isset = !!user.village
|
||||
newData.avatar = user.avatar
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { CustomRequestOptions } from '@/interceptors/request'
|
||||
|
||||
import { useUserStore } from '@/store'
|
||||
export function http<T>(options: CustomRequestOptions) {
|
||||
// 1. 返回 Promise 对象
|
||||
return new Promise<IResData<T>>((resolve, reject) => {
|
||||
@ -10,14 +10,15 @@ export function http<T>(options: CustomRequestOptions) {
|
||||
responseType: 'json',
|
||||
// #endif
|
||||
// 响应成功
|
||||
success(res) {
|
||||
async success(res) {
|
||||
// 状态码 2xx,参考 axios 的设计
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
// 2.1 提取核心数据 res.data
|
||||
resolve(res.data as IResData<T>)
|
||||
} else if (res.statusCode === 401) {
|
||||
// 401错误 -> 清理用户信息,跳转到登录页
|
||||
// userStore.clearUserInfo()
|
||||
const userStore = useUserStore()
|
||||
await userStore.logout()
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: (res.data as IResData<T>).msg || '请登录',
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { pages, subPackages } from '@/pages.json'
|
||||
import { isMpWeixin } from './platform'
|
||||
|
||||
import { getInfoAPI } from '@/service/crmeb/product.ts'
|
||||
import { http } from '@/utils/http'
|
||||
export function getLastPage() {
|
||||
// getCurrentPages() 至少有1个元素,所以不再额外判断
|
||||
// const lastPage = getCurrentPages().at(-1)
|
||||
@ -219,11 +220,38 @@ export function getShopWebUrl(url) {
|
||||
import { useUserStore } from '@/store'
|
||||
// const userStore = useUserStore()
|
||||
// 代登录跳转
|
||||
export function hasLogin() {
|
||||
const hasLogin = useUserStore().userInfo.id ? true : false
|
||||
// console.log(useUserStore().userInfo)
|
||||
// console.log('是否登录', hasLogin)
|
||||
// console.log('是否登录sss', useUserStore().userInfo)
|
||||
export async function hasLogin() {
|
||||
const res = await getInfoAPI()
|
||||
// const res = await http.get('/api/user/info', {})
|
||||
console.log('hasLogin', res)
|
||||
if (res.code === 401) {
|
||||
const hasLogin = false
|
||||
//强制跳转设置村庄
|
||||
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
|
||||
} else {
|
||||
const hasLogin = true
|
||||
//强制跳转设置村庄
|
||||
if (hasLogin && !useUserStore().userInfo.isset) {
|
||||
// if (!this.phone) {
|
||||
@ -249,3 +277,4 @@ export function hasLogin() {
|
||||
//返回是否登录
|
||||
return hasLogin
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user