27 changed files with 169 additions and 260 deletions
-
97App.vue
-
10api/user.js
-
61pages/home/home.vue
-
2pages/lendCar/lendCar.vue
-
6pages/login/login.vue
-
4pages/search/search.vue
-
2pages/user/user.vue
-
15subpkg/pages/activity-detail/activity-detail.vue
-
6subpkg/pages/activity-record/activity-record.vue
-
8subpkg/pages/agreement/agreement.vue
-
6subpkg/pages/book-detail/book-detail.vue
-
9subpkg/pages/book-list/book-list.vue
-
12subpkg/pages/collect-list/collect-list.vue
-
6subpkg/pages/feedback-detail/feedback-detail.vue
-
6subpkg/pages/feedback-list/feedback-list.vue
-
13subpkg/pages/feedback/feedback.vue
-
20subpkg/pages/myLending/myLending.vue
-
10subpkg/pages/ranking/ranking.vue
-
24subpkg/pages/reader-card/reader-card.vue
-
6subpkg/pages/register/register-form.vue
-
2subpkg/pages/register/register.vue
-
60subpkg/pages/seat-booking/seat-booking.vue
-
9subpkg/pages/seat-record/seat-record.vue
-
10subpkg/pages/user-info/user-info.vue
-
1utils/config.js
-
18utils/global.js
-
6utils/storage.js
@ -1,32 +1,71 @@ |
|||
<script> |
|||
export default { |
|||
onLaunch: function() { |
|||
console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!') |
|||
console.log('App Launch') |
|||
}, |
|||
onShow: function() { |
|||
console.log('App Show') |
|||
}, |
|||
onHide: function() { |
|||
console.log('App Hide') |
|||
} |
|||
} |
|||
</script> |
|||
import { FetchLibcodeBycode } from '@/api/user' |
|||
|
|||
export default { |
|||
globalData: { |
|||
appid: '', |
|||
libcode: '', // 全局libcode,所有页面 getApp().globalData.libcode 访问 |
|||
}, |
|||
onLaunch() { |
|||
this.initAppIdAndLibcode() |
|||
}, |
|||
methods: { |
|||
// 初始化:拿appid → 请求接口拿libcode,存入globalData |
|||
async initAppIdAndLibcode() { |
|||
// #ifdef MP-WEIXIN |
|||
try { |
|||
// 1、全局获取appid |
|||
const accountInfo = wx.getAccountInfoSync() |
|||
const appid = accountInfo.miniProgram.appId |
|||
this.globalData.appid = appid |
|||
|
|||
<style lang="scss"> |
|||
/*每个页面公共css */ |
|||
@import '@/uni_modules/uni-scss/index.scss'; |
|||
/* #ifndef APP-NVUE */ |
|||
@import '@/static/customicons.css'; |
|||
// 设置整个项目的背景色 |
|||
page { |
|||
background-color: #f5f5f5; |
|||
} |
|||
// 优先读本地缓存libcode,减少接口请求 |
|||
let cacheLibcode = uni.getStorageSync('GLOBAL_LIBCODE') |
|||
if(cacheLibcode){ |
|||
this.globalData.libcode = cacheLibcode |
|||
console.log('使用缓存libcode:', cacheLibcode) |
|||
return |
|||
} |
|||
// 2、调用接口 FetchLibcodeBycode,传入appid获取libcode |
|||
const res = await FetchLibcodeBycode({ |
|||
code: 'vx_mini_appId', |
|||
value: appid |
|||
}) |
|||
if(res.code === 200 && res.data){ |
|||
const libcode = res.data |
|||
this.globalData.libcode = libcode |
|||
uni.setStorageSync('GLOBAL_LIBCODE', libcode) |
|||
console.log('接口获取全局libcode成功:', libcode) |
|||
}else{ |
|||
console.error('FetchLibcodeBycode 获取libcode失败', res) |
|||
} |
|||
} catch(e){ |
|||
console.error('初始化appid/libcode异常', e) |
|||
} |
|||
// #endif |
|||
}, |
|||
// 退出登录 待用 |
|||
// logout(){ |
|||
// // 1. 清除登录缓存 |
|||
// uni.removeStorageSync('wx_login_code') |
|||
// uni.removeStorageSync('READER_CARD_LIST') |
|||
// uni.removeStorageSync('CURRENT_READER_CARD') |
|||
|
|||
/* #endif */ |
|||
.example-info { |
|||
font-size: 14px; |
|||
color: #333; |
|||
padding: 10px; |
|||
} |
|||
</style> |
|||
// // 2.清除libcode缓存,强制重新拉取 |
|||
// uni.removeStorageSync('GLOBAL_LIBCODE') |
|||
// getApp().globalData.libcode = '' |
|||
|
|||
// // 跳转登录页 |
|||
// uni.reLaunch({url:'/pages/login/login'}) |
|||
// } |
|||
// 刷新libcode 待用 |
|||
// refreshLibcode(){ |
|||
// uni.removeStorageSync('GLOBAL_LIBCODE') |
|||
// getApp().globalData.libcode = '' |
|||
// uni.showToast({title:"已重置libcode,将重新获取",icon:"none"}) |
|||
// // 重新执行App.vue里面的初始化方法 |
|||
// getApp().$options.methods.initAppIdAndLibcode() |
|||
// } |
|||
} |
|||
} |
|||
</script> |
|||
@ -0,0 +1,18 @@ |
|||
// utils/global.js
|
|||
export function waitLibcodeReady(){ |
|||
return new Promise((resolve)=>{ |
|||
const app = getApp() |
|||
if(app.globalData.libcode){ |
|||
return resolve(app.globalData.libcode) |
|||
} |
|||
// 轮询等待,最多3秒
|
|||
let count = 0 |
|||
const timer = setInterval(()=>{ |
|||
count++ |
|||
if(app.globalData.libcode || count>30){ |
|||
clearInterval(timer) |
|||
resolve(app.globalData.libcode || '') |
|||
} |
|||
},100) |
|||
}) |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue