master
lion 2 months ago
parent e79ce820ba
commit 61a6ee5618

@ -0,0 +1,37 @@
/**
* 未登录时不强制跳转仅在用户主动操作下单加购等时提示登录
*/
export function getToken(vm) {
return vm?.vuex_token || uni.getStorageSync('lifeData')?.vuex_token || ''
}
/**
* @returns {Promise<boolean>} 用户确认去登录为 true
*/
export function promptLogin(vm, options = {}) {
const {
title = '提示',
content = '登录后可继续操作,是否前往登录?',
confirmText = '去登录',
} = options
return new Promise((resolve) => {
uni.showModal({
title,
content,
confirmText,
cancelText: '暂不登录',
success: (res) => {
if (res.confirm) {
vm.$u.route({
url: '/pages/login/login',
type: 'navigateTo',
})
resolve(true)
} else {
resolve(false)
}
},
fail: () => resolve(false),
})
})
}

@ -33,18 +33,22 @@ const install = (Vue, vm) => {
if (res.statusCode === 200) {
if (res.data.hasOwnProperty("errcode")) {
if (res.data.errcode === 40001) {
Vue.prototype.$u.debounce(() => {
uni.showToast({
icon: "none",
title: "登陆过期,请重新登录"
})
setTimeout(() => {
uni.redirectTo({
url: '/pages/login/login'
const token = vm.vuex_token || uni.getStorageSync('lifeData')?.vuex_token;
// 仅已登录用户 token 失效时引导重新登录;未登录浏览不强制跳转
if (token) {
Vue.prototype.$u.debounce(() => {
uni.showToast({
icon: "none",
title: "登陆过期,请重新登录"
})
}, 1500)
})
setTimeout(() => {
uni.navigateTo({
url: '/pages/login/login'
})
}, 1500)
})
}
return false
} else {
uni.showToast({
icon: "none",

@ -95,11 +95,12 @@
</template>
<script>
import { getToken, promptLogin } from '@/common/auth.js'
export default {
data() {
return {
id: '',
choose_site:'',
id: '',
choose_site:'',
site_name:'',
currentTab: 0,
info: {},
@ -117,8 +118,8 @@
uni.setNavigationBarTitle({
title: option.title ?? "服务项目"
});
this.id = option.id ? option.id : ''
this.choose_site = option.choose_site?option.choose_site:''
this.id = option.id ? option.id : ''
this.choose_site = option.choose_site?option.choose_site:''
this.site_name = option.site_name?option.site_name:''
this.getDetail(this.id)
},
@ -127,13 +128,13 @@
},
computed: {
token() {
return this.vuex_token || uni.getStorageSync('lifeData')?.vuex_token
return getToken(this)
}
},
methods: {
async getDetail(id) {
await this.$u.api.accompanyProductDetail({
id: id,
id: id,
site_id:this.choose_site
}).then(res=>{
console.log("res", res)
@ -141,25 +142,12 @@
})
},
toOrder(info) {
async toOrder(info) {
if (!this.token) {
uni.showModal({
title: "提示",
content: "请先登录再下单",
confirmText: "登录",
success: (status) => {
if (status.confirm) {
this.$u.route({
url: '/pages/login/login',
type: 'redirect'
})
} else {
}
},
fail: () => {},
});
return
const ok = await promptLogin(this, {
content: '登录后可预约服务,是否前往登录?',
})
if (!ok) return
}
this.$u.route({
url: '/package_sub/pages/AddOrder/AddOrder?id='+info.id+'&site_name='+this.site_name+'&site_id='+this.choose_site+'&type='+info.type+'&can_multi_num='+info.can_multi_num

@ -56,6 +56,7 @@
</template>
<script>
import { getToken, promptLogin } from '@/common/auth.js'
export default {
data() {
return {
@ -72,7 +73,7 @@
select: {
page: 1,
page_size: 5,
type: '',
type: '',
site_id:''
},
list: [],
@ -81,7 +82,7 @@
list_site: [{
id: '',
name: '全部'
}],
}],
site_name:''
@ -93,8 +94,8 @@
// }
},
onLoad(options) {
this.select.type = options.type ? options.type : ''
this.select.site_id = this.vuex_site?this.vuex_site.id:''
this.select.type = options.type ? options.type : ''
this.select.site_id = this.vuex_site?this.vuex_site.id:''
this.site_name = this.vuex_site?this.vuex_site.name:'全部'
this.getSiteList()
this.getList()
@ -125,32 +126,19 @@
},
confirmSite(e) {
// this.$u.vuex("vuex_site", e[0])
console.log(e[0])
this.select.site_id = e[0].id?e[0].id:''
console.log(e[0])
this.select.site_id = e[0].id?e[0].id:''
this.site_name = e[0].name?e[0].name:'全部'
this.list = []
this.select.page = 1
this.getList()
},
toOrder(item) {
async toOrder(item) {
if (!this.token) {
uni.showModal({
title: "提示",
content: "请先登录再下单",
confirmText: "登录",
success: (status) => {
if (status.confirm) {
this.$u.route({
url: '/pages/login/login',
type: 'redirect'
})
} else {
}
},
fail: () => {},
});
return
const ok = await promptLogin(this, {
content: '登录后可预约服务,是否前往登录?',
})
if (!ok) return
}
this.$u.route({
url: '/package_sub/pages/AddOrder/AddOrder',
@ -170,7 +158,7 @@
},
computed: {
token() {
return this.vuex_token || uni.getStorageSync('lifeData')?.vuex_token
return getToken(this)
}
}
}

@ -341,7 +341,7 @@
</button>
<view
class="item car"
@tap="$u.route({ url: '/package_sub/pages/Shop/Cart' })"
@tap="goCart"
>
<u-badge
class="car-num"
@ -373,6 +373,8 @@
</template>
<script>
import { getToken, promptLogin } from '@/common/auth.js'
export default {
data() {
return {
@ -416,6 +418,9 @@ export default {
};
},
computed: {
token() {
return getToken(this)
},
menuButtonLeft() {
return (
uni.getSystemInfoSync().windowWidth -
@ -472,6 +477,10 @@ export default {
});
},
async getCartNum() {
if (!this.token) {
this.cartNum = 0
return
}
try {
const res = await this.$u.api.cartList({
page: 1,
@ -480,6 +489,17 @@ export default {
this.cartNum = res.total;
} catch (err) {}
},
goCart() {
if (!this.token) {
promptLogin(this, { content: '登录后可查看购物车,是否前往登录?' })
return
}
this.$u.route({ url: '/package_sub/pages/Shop/Cart' })
},
async ensureLoginForPurchase() {
if (this.token) return true
return promptLogin(this, { content: '登录后可购买商品,是否前往登录?' })
},
async getComment() {
this.commentList = [
{
@ -604,6 +624,7 @@ export default {
},
async confirm() {
try {
if (!(await this.ensureLoginForPurchase())) return
if (this.isSkuSubmit) {
if (!this.form.product_sku_id) {
this.$refs.uToast.show({
@ -637,7 +658,9 @@ export default {
},
created() {
this.getRecommendPro();
this.getCartNum();
if (this.token) {
this.getCartNum();
}
this.getComment();
},
onLoad(option) {
@ -646,6 +669,11 @@ export default {
this.getDetail(option.id);
}
},
onShow() {
if (this.token) {
this.getCartNum();
}
},
onPageScroll({ scrollTop }) {
if (this.timer) return;
this.timer = setTimeout(() => {

Loading…
Cancel
Save