|
@@ -0,0 +1,321 @@
|
|
|
+//app.js
|
|
|
+import { systemInfo, routers, isFn, getGlobalVal, getWxUserInfoSetting, getUpdateManager } from './utils/util.js'
|
|
|
+import { WxLogin, FirstWxLogin, GetMineInfo } from './utils/api.js'
|
|
|
+const { reLaunch, redirectTo } = routers()
|
|
|
+
|
|
|
+App({
|
|
|
+ onLaunch: function (options) {
|
|
|
+ this.globalData.options = options
|
|
|
+ getUpdateManager()
|
|
|
+ wx.getSystemInfo({
|
|
|
+ success: e => {
|
|
|
+ let modelmes = e.model;
|
|
|
+ if (modelmes.search('iPhone X' || 'iPhone 11') != -1) {
|
|
|
+ this.globalData.isIphoneX = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ wx.onMemoryWarning(function (e) {
|
|
|
+ console.log('onMemoryWarningReceive', e)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ onShow: function (options) {
|
|
|
+ this.globalData.options = options
|
|
|
+ },
|
|
|
+
|
|
|
+ onHide: function (e) {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ onError: function (e) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '程序执行失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ onPageNotFound: function (e) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '没有找到对应页面',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ redirectTo({ url: 'pages/index/index' })
|
|
|
+ }, 2000)
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化
|
|
|
+ */
|
|
|
+ init: function () {
|
|
|
+ // redirectTo({ url: 'president/pages/home/home' })
|
|
|
+ // reLaunch({ url: 'dispatcher/pages/withdraw/withdraw'})
|
|
|
+ // reLaunch({ url: 'dispatcher/pages/dispatch_go/dispatch_go'})
|
|
|
+ // reLaunch({ url: 'parents/pages/home/home'})
|
|
|
+ // reLaunch({ url: 'dispatcher/pages/home/home' })
|
|
|
+ // return
|
|
|
+
|
|
|
+ const userInfo = getGlobalVal('userInfo')
|
|
|
+ getWxUserInfoSetting((type, res) => {
|
|
|
+ // if (type != 1 || !userInfo) {
|
|
|
+ // redirectTo({ url: 'pages/wx_authority/wx_authority' })
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ this.globalData.userInfo = userInfo
|
|
|
+ wx.checkSession({
|
|
|
+ success: res => {
|
|
|
+ const arr1 = ['accessToken', 'userInfo', 'userId']
|
|
|
+ const arr2 = ['vipList', 'vip', 'vipIndex', 'vipId']
|
|
|
+ const temp = {}
|
|
|
+ for (let i in arr1) {
|
|
|
+ temp[arr1[i]] = getGlobalVal(arr1[i])
|
|
|
+ }
|
|
|
+ for (let i in arr2) {
|
|
|
+ temp[arr2[i]] = getGlobalVal(arr2[i], `${arr2[i]}_${temp['userId']}`)
|
|
|
+ }
|
|
|
+ for (let i in temp) {
|
|
|
+ this.globalData[i] = temp[i]
|
|
|
+ }
|
|
|
+
|
|
|
+ this.permissionsJumpFn()
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ this.login()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取微信code
|
|
|
+ */
|
|
|
+ getWxloginCode: function (cb) {
|
|
|
+ wx.login({
|
|
|
+ success: res => {
|
|
|
+ if (isFn(cb)) cb(res.code)
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ wx.showToast({
|
|
|
+ title: '获取微信code失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取微信用户信息
|
|
|
+ */
|
|
|
+ login: function () {
|
|
|
+ this.getWxloginCode(code => {
|
|
|
+ WxLogin({ data: { code } }).then(this.handleLogin).catch(e => {
|
|
|
+ if (e.data.code == '888') {
|
|
|
+ redirectTo({ url: 'pages/wx_authority/wx_authority' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理登录信息
|
|
|
+ */
|
|
|
+ handleLogin: function (res) {
|
|
|
+ const { accessToken, userId, isDispatcher, list } = res.data
|
|
|
+ const arr = { accessToken, userId, isDispatcher, list }
|
|
|
+ for (let i in arr) {
|
|
|
+ this.globalData[i] = arr[i]
|
|
|
+ wx.setStorageSync(i, arr[i])
|
|
|
+ }
|
|
|
+ this.permissionsJumpFn()
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 权限跳转
|
|
|
+ */
|
|
|
+ permissionsJumpFn: function (e) {
|
|
|
+ const { tempOptions, options } = this.globalData
|
|
|
+ const isDispatcher = getGlobalVal('isDispatcher')
|
|
|
+ const userId = getGlobalVal('userId')
|
|
|
+ const libId = getGlobalVal(`dispatchLibId_${userId}`)
|
|
|
+ const userInfo = getGlobalVal('userInfo')
|
|
|
+ const { query = {}, scene, path } = options || tempOptions
|
|
|
+ let url = ''
|
|
|
+ if (query && query.type > 1) {
|
|
|
+ url = path ? path : 'pages/index/index'
|
|
|
+ } else {
|
|
|
+ // url = 'dispatcher/pages/sweeped_books/sweeped_books'
|
|
|
+ if (isDispatcher == 1) {
|
|
|
+ if (!userInfo) {
|
|
|
+ redirectTo({ url: 'pages/wx_authority/wx_authority' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (libId) {
|
|
|
+ // url = 'dispatcher/pages/dispatch_leave/dispatch_leave'
|
|
|
+ url = 'dispatcher/pages/dispatch_go/dispatch_go'
|
|
|
+ } else {
|
|
|
+ url = 'dispatcher/pages/home/home'
|
|
|
+ }
|
|
|
+ } else if (isDispatcher == 3) {
|
|
|
+ // console.log('111')
|
|
|
+ if (!userInfo) {
|
|
|
+ redirectTo({ url: 'pages/wx_authority/wx_authority' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ url = 'president/pages/home/home'
|
|
|
+ } else {
|
|
|
+ url = 'parents/pages/main/main'
|
|
|
+ this.getVipList()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const paras = { ...query, url, scene }
|
|
|
+ // console.log(this.globalData)
|
|
|
+ // console.log(paras)
|
|
|
+ if (isFn(reLaunch)) reLaunch({ url, paras })
|
|
|
+ this.globalData.options = tempOptions
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取会员卡列表
|
|
|
+ */
|
|
|
+ getVipList: function () {
|
|
|
+ const continuousFn = { fn: this.getVipList, param: { ...arguments } }
|
|
|
+ const userId = getGlobalVal('userId')
|
|
|
+ const vipId = getGlobalVal('vipId', `vipId_${userId}`)
|
|
|
+ const { noVipListToastText } = this.globalData
|
|
|
+ const fn = (i, v) => {
|
|
|
+ this.globalData['vip'] = v
|
|
|
+ wx.setStorageSync(`vip_${userId}`, v)
|
|
|
+
|
|
|
+ this.globalData['vipIndex'] = i
|
|
|
+ wx.setStorageSync(`vipIndex_${userId}`, i)
|
|
|
+
|
|
|
+ this.globalData['vipId'] = v['vip_id']
|
|
|
+ wx.setStorageSync(`vipId_${userId}`, v['vip_id'])
|
|
|
+ }
|
|
|
+ GetMineInfo({ continuousFn }).then(res => {
|
|
|
+ const { vipList = null } = res.data
|
|
|
+ if (vipList.length > 0) {
|
|
|
+ let isSame = false
|
|
|
+ for (let i in vipList) {
|
|
|
+ if (vipList[i]['vip_id'] == vipId) {
|
|
|
+ isSame = true
|
|
|
+ fn(i, vipList[i])
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!isSame) {
|
|
|
+ fn(0, vipList[0])
|
|
|
+ }
|
|
|
+ this.globalData['vipList'] = vipList
|
|
|
+ wx.setStorageSync(`vipList_${userId}`, vipList)
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: noVipListToastText,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存微信用户数据
|
|
|
+ */
|
|
|
+ saveUserInfo: function (res, code) {
|
|
|
+ const { accessToken, userId } = this.globalData
|
|
|
+ const { encryptedData, iv, signature, userInfo } = res
|
|
|
+ const user = Object.assign(userInfo, { encryptedData, iv, signature })
|
|
|
+ FirstWxLogin({ data: { code, ...user } }).then(res => {
|
|
|
+ this.globalData.userInfo = user
|
|
|
+ wx.setStorageSync('userInfo', user)
|
|
|
+ wx.setStorageSync('hiddenModel', true)
|
|
|
+ wx.setStorageSync('isfirstLogin', true)
|
|
|
+ wx.setStorageSync('hiddenGetallModel', true)
|
|
|
+ wx.setStorageSync('infofrominput', [])
|
|
|
+ this.handleLogin(res)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否有会员卡服务
|
|
|
+ */
|
|
|
+ hasVipService: function () {
|
|
|
+ const vipId = getGlobalVal('vipId')
|
|
|
+ if (vipId) {
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: this.globalData.noVipServiceToastText,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否有当前图书馆服务
|
|
|
+ */
|
|
|
+ hasLibraryService: function () {
|
|
|
+ const { stype = 0, id } = getGlobalVal('library')
|
|
|
+ if (!id) {
|
|
|
+ wx.showToast({
|
|
|
+ title: this.globalData.noLibraryToastText,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ if (stype == 1) {
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: this.globalData.noLibraryServiceToastText,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 全局变量
|
|
|
+ */
|
|
|
+ globalData: {
|
|
|
+ systemInfo,
|
|
|
+ wechatsys: systemInfo.version + ' ' + systemInfo.SDKVersion,
|
|
|
+ phoneimei: '',
|
|
|
+ phonesys: systemInfo.system,
|
|
|
+ phonetype: systemInfo.brand + ' ' + systemInfo.model,
|
|
|
+ version: '1.3.3',
|
|
|
+ platform: '3',
|
|
|
+ build: '1.3.3',
|
|
|
+ initStatus: 0,
|
|
|
+ loginTime: 0,
|
|
|
+ appid: 'wxe9cdca7c3365e448',
|
|
|
+ // host: 'https://t.sharingschool.com/gz',
|
|
|
+ // baseImgUrl: 'https://img.sharingschool.com',
|
|
|
+ // thumbnail: '?x-oss-process=image/resize,m_fill,h_300,w_200',
|
|
|
+ host: 'https://xt.sharingschool.com/gz',
|
|
|
+ baseImgUrl: 'https://xtimg.sharingschool.com',
|
|
|
+ thumbnail: '!t200x300.jpg',
|
|
|
+ tempOptions: { query: {}, path: 'pages/index/index', scene: 1001 },
|
|
|
+ options: null,
|
|
|
+ continuousFn: null,
|
|
|
+ accessToken: null,
|
|
|
+ userId: null,
|
|
|
+ vipList: null,
|
|
|
+ vip: null,
|
|
|
+ vipIndex: null,
|
|
|
+ vipId: null,
|
|
|
+ userInfo: null,
|
|
|
+ isIphoneX:null,
|
|
|
+ noVipListToastText: '您尚未开通私塾家共享图书馆借阅服务,请就近至私塾家共享图书馆开通服务',
|
|
|
+ noVipServiceToastText: '您非本馆会员,无法进行此操作,如想继续操作可联系管理员',
|
|
|
+ noLibraryServiceToastText: '您非本馆会员,无法进行此操作,请切换到您所在的馆继续操作',
|
|
|
+ noLibraryToastText: '您暂未选择图书馆,请回到首页进行定位匹配',
|
|
|
+ noBorrowToastText: '您已经预约过此书',
|
|
|
+ qrcodeInvalidToastText: '二维码已失效',
|
|
|
+ borrowToastText: '此书库存有货,点击我想借阅将在下一次调书时移至您的服务所在馆',
|
|
|
+ reservationsToastText: '您可直接扫描书本上二维码借阅,也可预约,如预约,其他人将暂时不可借。',
|
|
|
+ wishToastText: '更多人将此书加入心愿单会成为我们的优先采购书籍'
|
|
|
+ }
|
|
|
+})
|