123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <template>
- <div>
- <!-- <div @click="scanQRCode">scanQRCode</div> -->
- <keep-alive v-if="isInit" :include="cachedViews" :max="15">
- <router-view :key="key" />
- </keep-alive>
- <div v-else>
- <br />
- <br />
- <van-skeleton title :row="3" />
- <br />
- <br />
- <van-skeleton title :row="4" />
- <br />
- <br />
- <van-skeleton title :row="3" />
- <br />
- <br />
- <van-skeleton title :row="4" />
- <br />
- <br />
- </div>
- <wx-points-commit ref="wxPointsCommit"></wx-points-commit>
- </div>
- </template>
- <script>
- import loginMinix from '@/mixins/login';
- import {
- getIsMin, getIsWxh5, getUrlParams, initEnv, requestInit,
- wssInit, theCommunicationBetweenWechatAndH5IsNormal,
- isReloadBefore, getsTheCurrentTopic, alipayClientInit,
- localStorageInit, setToken, windowSendInit, getQuery
- } from '@/utils/index.js';
- import uni from '@/utils/uniHooks';
- import { getAppIdByGroupIdAndMallId } from '@/utils/index.js';
- import sensorsFn from '@/plugins/sensors';
- import {getTokenById} from '@/utils/api-kip'
- import { initWxJsSdkConfig } from '@/utils/login';
- export default {
- mixins: [loginMinix],
- async created() {
-
- await initEnv();
- await requestInit();
- await this.init();
- // await sensorsFn(); // 埋点初始化
- // 初始化环境变量
- },
- computed: {
- cachedViews() {
- return this.$store.state.cachedViews.cachedViews;
- },
- passLogin() {
- return this.$store.state.passLogin;
- },
- key() {
- return this.$route.path;
- },
- isInit() {
- return this.$store.state.isInit;
- },
- },
- watch: {
- cachedViews() {
- console.log('cachedViews(打印已经缓存的页面)', this.cachedViews);
- },
- $route: {
- immediate: true,
- handler(route) {
- const {
- name,
- meta: { keepAlive },
- } = route;
- if (name && keepAlive) {
- this.$store.commit('cachedViews/ADD_CACHED_VIEW', route);
- }
- },
- },
- },
- methods: {
- scanQRCode() {
- try {
- // 验证 jsdk
- this.$wx.scanQRCode({
- desc: 'scanQRCode desc',
- needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
- // scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
- success: ( res ) => {
- console.log(237,res);
- // runScanFn(res);∑
- // this.formMsg.deviceCode = res.resultStr;
- },
- error: ( res ) => {
- console.log(242,res);
- },
- });
- } catch (err) {
- console.log(99, err);
- }
-
- },
- async init() {
- window.isWxV2 = false
- // this.$store.commit('SET_IS_INIT', true);
- // return
- // 微信重构改造 第二版本
- if(window.location.href.indexOf('tparking/wxV2') > -1) {
- localStorageInit();
- window.isWxV2 = true
-
- uni.showLoading({
- title: '加载中',
- });
- console.log(window.location.search);
-
- const options = getQuery(window.location.href)
- // 获取 token
- let accessToken = ''
- if(options.sessionId) {
- accessToken = await getTokenById({
- tokenId: options.sessionId
- })
- }
- this.$store.dispatch('baseInitV2', {
- options: {
- ...options,
- accessToken: accessToken
- },
- callback: () => {
- console.log(108, this.$route);
- this.$store.commit('SET_IS_INIT', true);
- // 缓存
- // this.$store.commit('cachedViews/ADD_CACHED_VIEW', {
- // name: 'wxV2'
- // });
- // 无感积分逻辑
- // this.wxEasyPointsCommitStatusInit();
- },
- });
- return
- }
- uni.setStorageSync('env', window.env);
- // 如果是支付宝小程序:初始化
- if (isAlipayClient) {
- setToken()
- localStorageInit();
- windowSendInit()
- try {
- this.$store.commit('SET_IS_INIT', false);
- const options = await alipayClientInit();
- await this.$store.dispatch('baseInit', {
- options,
- callback: () => {
- this.$store.commit('SET_IS_INIT', true);
- // 无感积分逻辑
- // this.wxEasyPointsCommitStatusInit();
- },
- });
- } catch (err) {
- console.log(err);
- }
- return
- }
- // 如果是微信小程序。初始化wss
- if (getIsMin()) {
- // 如果刷新之后没有与微信小程序建立链接则提示用户,关闭小程序重新进入
- const isReloadLoop = await isReloadBefore();
- if (isReloadLoop) {
- uni.removeStorageSync('isReload');
- const { theme } = getsTheCurrentTopic();
- this.$dialog({
- title: '温馨提示',
- message: '当前网络异常,请重新进入小程序',
- confirmButtonColor: this.$theme[theme].primaryColor,
- });
- return;
- /* const isReload = await theCommunicationBetweenWechatAndH5IsNormal();
- if (isReload) {
- uni.removeStorageSync('isReload');
- const { theme } = getsTheCurrentTopic();
- this.$dialog({
- title: '温馨提示',
- message: '当前网络异常,请重新进入小程序',
- confirmButtonColor: this.$theme[theme].primaryColor,
- });
- return;
- } */
- }
- if (window.location.href.indexOf('cryptojs') > -1) {
- return;
- }
- // // 保留 carList
- // const carList = uni.getStorageSync('carList');
- // // 保留 buildingId
- // const buildingId = window.localStorage.getItem('buildingId')
- // // 每次进入页面清空 缓存数据
- // window.localStorage.clear();
- // if (carList) {
- // uni.setStorageSync('carList', JSON.parse(carList));
- // }
- // if (buildingId) {
- // window.localStorage.setItem('buildingId', buildingId)
- // }
- setToken();
- localStorageInit();
- this.$store.commit('SET_IS_INIT', false);
- try {
- const options = await wssInit();
- this.$store.dispatch('baseInit', {
- options,
- callback: () => {
- this.$store.commit('SET_IS_INIT', true);
- // 无感积分逻辑
- // this.wxEasyPointsCommitStatusInit();
- },
- });
- } catch (err) {
- console.log(err);
- }
- }
- // 如果是微信公众号
- if (getIsWxh5()) {
- // 判断用户是否登录
- this.micromessengerInit();
- }
- },
- micromessengerInit() {
- this.$store.commit('SET_IS_INIT', false);
- let path = '';
- let [groupId, mallId] = window.location.pathname.split('/').filter((elm) => elm);
- // return;
- // 如果groupId 是 tparking
- if (groupId === 'tparking') {
- [path, groupId, mallId] = window.location.pathname.split('/').filter((elm) => elm);
- }
- if (!groupId || !mallId) {
- groupId = uni.getStorageSync('groupId');
- mallId = uni.getStorageSync('mallId');
- }
- this.$store.commit('SET_GROUP_ID', groupId);
- this.$store.commit('SET_MALL_ID', mallId);
- // 设置appid
- const appid = getAppIdByGroupIdAndMallId({
- groupId,
- mallId,
- type: 'appid',
- });
- uni.setStorageSync('appid', appid);
- // 如果用户没有openid
- const openid = uni.getStorageSync('openid');
- const query = getUrlParams();
- // return;
- // 设置openid
- this.$nextTick(() => {
- this.$store.commit('SET_IS_INIT', true);
- if (openid && openid !== 'undefined') {
- this.$store.commit('SET_OPENID', openid);
- // 用户选择不登录
- if (this.isLogin !== 'loginDenied') {
- this.$store.commit('SET_IS_INIT', false);
- setTimeout(() => {
- this.$store.commit('SET_IS_INIT', true);
- }, 700);
- // 判断用户是否需要登录
- this.checkIsLogin(() => {
- this.$store.commit('SET_IS_INIT', true);
- // window.location.reload();
- this.$store.dispatch('getUserDetail');
- this.$store.commit('SET_MEMBER', uni.getStorageSync('member'));
- // 无感积分逻辑
- this.wxEasyPointsCommitStatusInit();
- // uni.getStorageSync();
- });
- }
- } else {
- // 前往授权页面
- if (this.$route.path.indexOf('openWx') < 0) {
- let openWxPath = 'openWx';
- if (this.$route.fullPath === '/') {
- openWxPath = `/${groupId}/${mallId}/openWx`;
- }
- this.$router.push({
- path: openWxPath,
- query,
- });
- }
- }
- });
- },
- // 无感积分相关
- async wxEasyPointsCommitStatusInit() {
- return;
- this.$refs.wxPointsCommit.open();
- // 判断用户是否登陆
- if (uni.getStorageSync('openid') && uni.getStorageSync('member') && uni.getStorageSync('member') !== {}) {
- const easyPointsCommitStatus = await getWxEasyPointsCommitStatus();
- if (easyPointsCommitStatus) {
- this.$refs.wxPointsCommit.open();
- }
- }
- },
- },
- };
- </script>
- <style lang="less">
- /* 如果有其他引入,合并即可,该文件最好放第一行 */
- // @import '@kip/ui-mobile/theme/theme.css';
- @import '~@/kui/theme/theme.css';
- </style>
- <style>
- page {
- display: flex;
- flex-direction: column;
- height: 100%;
- }
- body {
- padding: 0;
- margin: 0;
- }
- </style>
|