| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import store from '@/store'
- import { mapGetters,mapActions } from 'vuex'
- import { pageTo, isLogin } from '@/utils/util.js'
- import { getUser, wxMiniLogin } from '@/utils/auth'
- import { getDictionaries } from '@/api/mini'
- import { hasTokenAutoLogin } from '@/api/common'
- export default {
- mixins: [],
- data() {
- return {
- // 全局混入,插入链接参数
- option: null,
- // 全局混入,插入全局常量
- constant: this.$constant,
- // 全局混入,插入全局工具函数
- $util: this.$util,
- // 全局混入,插入全局跳转函数
- pageTo: pageTo,
- shopAdminId: null,
- //所有花材列表
- allProduct:[],
- //零售店对应的id
- skCustomId:0
- }
- },
- computed: {
- ...mapGetters(["getLoginInfo","getSelectInfo"]),
- },
- onLoad: function (option) {
- this.option = option || null
- if (option.token) {
- uni.setStorageSync('token', option.token)
- }
- if (option.account) {
- uni.setStorageSync('account', option.account)
- }
- uni.setStorageSync('currentQuery', JSON.stringify(option))
- //pda监听获取不到option,通过存到storage传进去
- if(option.customId){
- uni.setStorageSync('pdaCustomId', option.customId)
- }else{
- uni.removeStorageSync('pdaCustomId')
- }
- if(this.$util.isEmpty(this.getLoginInfo)){
- var pages = getCurrentPages()
- let currentRoute = pages[pages.length-1].route;
- let token = uni.getStorageSync('token')
- if(this.$util.isEmpty(token)){
- if(currentRoute == 'pages/home/cash'){
- // #ifdef MP-WEIXIN
- wxMiniLogin(true).then(res => {
- //用于开启小程序自动登录
- let currentMiniOpenId = res.data.currentMiniOpenId || ''
- uni.setStorageSync('currentMiniOpenId', currentMiniOpenId)
- let token = res.token || ''
- if (!this.$util.isEmpty(token)) {
- getUser(true)
- }
- if (this.init) {
- this.init()
- }
- })
- // #endif
- }
- }else{
- let that = this
- hasTokenAutoLogin().then(subRes=>{
- if(subRes.code != 1){
- return
- }
- getDictionaries({ token: subRes.data.token }).then(res => {
- if (!that.$util.isEmpty(res)) {
- store.commit('setDictionariesInfo', { ...res.data.dict, ...res.data })
- store.commit('setMyShopInfo', { ...res.data.shop, ...res.data })
- }
- })
- store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
- this.skCustomId = subRes.data.skCustomId
- if (this.init) {
- this.init()
- }
- })
- }
- }
- },
- onShow(){
- if (isLogin()&&!this.$util.isEmpty(this.getLoginInfo)) {
- if (this.init) {
- this.init()
- }
- }
- },
- methods: {
- }
- }
|