| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import { mapGetters,mapActions } from 'vuex'
- import { pageTo } from '@/utils/util.js'
- import { getUser, wxLoginFn } from '@/utils/auth'
- import { getDictionaries } from '@/api/mini'
- import { hasTokenAutoLogin } from '@/api/common'
- import constant from '@/constant'
- export default {
- data() {
- return {
- // 全局混入,插入链接参数
- option: null,
- // 全局混入,插入全局常量
- constant: this.$constant,
- // 全局混入,插入全局工具函数
- $util: this.$util,
- // 全局混入,插入全局跳转函数
- pageTo: pageTo,
- shopAdminId: null,
- MODEL_TITLE: '',
- EXPER_AUTH_SHOW: false
- }
- },
- computed: {
- ...mapGetters({ loginInfo: "getLoginInfo" }),
- ...mapGetters(["getLoginInfo"])
- },
- 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))
- if (this.$util.isEmpty(this.getLoginInfo)) {
- // #ifdef MP-WEIXIN
- //微信小程序第一次打开小程序时尝试登录一次
- var pages = getCurrentPages()
- let currentRoute = pages[pages.length-1].route;
- let token = uni.getStorageSync('token')
- if(this.$util.isEmpty(token)){
- if(currentRoute == 'admin/home/workbench' || currentRoute == 'pagesPurchase/ghsProduct'){
- wxLoginFn(true).then(res => {
- let token = res.data.token || ''
- //用于开启小程序自动登录
- let currentMiniOpenId = res.data.currentMiniOpenId || ''
- uni.setStorageSync('currentMiniOpenId', currentMiniOpenId)
- if (!this.$util.isEmpty(token)) {
- getUser(true)
- this.setUserShopAll()
- }
- if (this.init) {
- this.init()
- }
- })
- }
- }else{
- let that = this
- hasTokenAutoLogin().then(subRes=>{
- //有几个地方涉及登陆,需要统一方法,请搜索关键词 uni_login
- if(subRes.code == 1){
- uni.setStorageSync('shopId', subRes.data.admin.currentShopId)
- getDictionaries({ token: subRes.data.token }).then(res => {
- if (that.$util.isEmpty(res)) {
- return false
- }
- that.$store.commit('setDictionariesInfo', { ...res.data.dict, ...res.data })
- that.$store.commit('setMyShopInfo', { ...res.data.shop, ...res.data })
- })
- that.$store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
- getUser(true).then(res => {
- uni.setNavigationBarTitle({ title: res.name })
- })
- that.setUserShopAll()
- }
- })
- }
- // #endif
- }
- },
- onShow(){
- if (this.init) {
- this.init()
- }
- },
- methods: {
- ...mapActions(['setUserShopAll'])
- },
- mounted() {
- if (this.mInit) {
- this.mInit()
- }
- }
- }
|