123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <script>
- import config from './config'
- import store from '@/store'
- import { getToken,getTokens,getSsoAdminToken } from '@/utils/auth'
- export default {
- onLaunch: function() {
- this.initApp()
- },
- methods: {
- // 初始化应用
- initApp() {
- // 初始化应用配置
- this.initConfig()
- // 检查用户登录状态
- //#ifdef H5
- //this.checkLogins()
- //#endif
- },
- initConfig() {
- this.globalData.config = config
- // if (this.globalData.config.VITE_SSO_LOGIN == true&&!getToken()) {
- // this.$tab.reLaunch('/pages/loginSso')
- // // getSsoToken();
- // };
- },
- checkLogin() {
- if (!getToken()) {
- this.$tab.reLaunch('/pages/login')
- }
- },
- checkLogins() {
- if (!getToken()) {
- // this.$tab.reLaunch('/pages/work/CleanGov/')
- // // 非静默授权,第一次有弹框
- this.code = ''
- var callback_url = 'https://tools-m.huaxiazhizao.com/#/pages/trade/shoe-style/index'
- // 获取页面url
- var appid = 'wx2cfd24c7380cdc08'
- this.code = this.getUrlCode().code
- // 截取code
- if (this.code == null || this.code === '') {
- // 如果没有code,则去请求
- window.location.href =
- `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent( callback_url )}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
- } else {
- // 当code不等于空时,调用后端接口获取用户信息
- this.getUserInfo()
- // 你自己的业务逻辑
- }
- }else{
- var options = uni.getStorageSync('options')
- if (options) {
- this.$tab.reLaunch('/pages/trade/shoe-style/ShoeStyleView')
- } else { //如果没有上一页返回首页
- this.$tab.reLaunch('/pages/trade/shoe-style/index')
- }
- }
- },
- getUrlCode() {
- // 截取url中的code方法
- var url = location.search
- var theRequest = new Object()
- if (url.indexOf('?') != -1) {
- var str = url.substr(1)
- var strs = str.split('&')
- for (var i = 0; i < strs.length; i++) {
- theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
- }
- }
- return theRequest
- },
- getUserInfo() {
- let data = {}
- data.code = this.code
- data.appid = 'wx2cfd24c7380cdc08'
- authorizeLogin(data).then(res => {
- uni.setStorageSync('X-Token', res.data.token)
- }).catch(() => {})
- },
- }
- }
- </script>
- <style lang="scss">
- @import '@/static/scss/index.scss'
- uni-list-item .uni-list-item__extra{
- flex:1
- }
- .uni-list-item .uni-list-item__content{
- flex: none;
- }
- </style>
|