App.vue 9.08 KB
<script>
import "./../.env.js";
import { AnalysysAgent } from "@/utils/analysys_paas.js";
import util from "@/utils/util.js";
import login from "@/utils/login.js";
import upload from '@/components/upload/task.js'
export default {
  globalData: {
    // 开发环境
    uniEnv: process.uniEnv,
    // 微信小程序平台编号,空--家维广场,1--自营平台
    wxAppNo: 1,

    // 服务规范教程视频
    service_standard: {
      course1: {
        url: process.uniEnv.qn_base_url + "course/Section1.mp4",
        title: "第一节 师傅考核规则",
        desc:
          "接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。",
      },
      course2: {
        url: process.uniEnv.qn_base_url + "course/Section2.mp4",
        title: "第二节 安装材料及工具",
        desc:
          "接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。",
      },
      course3: {
        url: process.uniEnv.qn_base_url + "course/Section3.mp4",
        title: "第三节 安装施工规范",
        desc:
          "接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。",
      },
      course4: {
        url: "https://qn-static.banshouhui.com/self-support/videoen.mp4",
        title: "第四节 录单上传要求",
        desc:
          "接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。",
      },
    },
    // 退出登录
    logout: false,
    navHeight: 0, //导航栏高度
    rpxScreenHeight: 0, // 照相视框高度
    safeHeight: 0, // 安全高度
    //拍照相关数据
    photo: {
      product: {
        brandId: "", // 品牌id
        brandName: "", // 品牌名称
        classifyId: "", // 分类id
        systemId: "", // 系统id
      },
      topIndex: 0,
      itemIndex: 0,
      currentItemLength: 0, //已拍摄照片张数
      productList: [],
      currentItem: null, // 选择的某一项
      setting: null, //自定义设置
      waterSetting: null, // 水印设置
      allImages: [],
      tempPath: {
        origin: "", // 缓存拍照图片
        mixWater: "", // 缓存水印拍照图片
      },
    },
	fileList: {} // 文件地址缓存 {url最后一段: tmpPath}
  },
  onLaunch: async function () {
    // 应用初始化(全局只触发一次)
    AnalysysAgent.registerSuperProperty("platform", "self-support");
    // 版本更新
    await this.updateApp();
    this.getSystemInfo();
    // 系统自动登录::每次运行小程序重新获取用户信息
    await this.autoLogin();

    //this.deleteTempImg()
  },
  onShow: function () {
    // 应用启动,或从后台进入前台显示
    if (this.uploadTask.length > 0) {
      upload.uploadImageTask(this)
    }
  },
  onHide: function () {
    // 应用从前台进入后台
  },
  watch: {
    uploadTask: function(newValue, oldValue) {
      if(newValue.length > 0) upload.uploadImageTask(this)
    }
  },
  methods: {
    // 处理已上传完成的图片
    deleteTempImg() {
      const result = uni.getStorageSync('delImg')
      if (result.length > 0) {
        for (let i of result) {
          uni.removeSavedFile({
            filePath: i
          })
        }
        uni.setStorageSync('delImg', [])
      }
    },
    getSystemInfo() {
      try {
        let a = this.$u.sys();
        this.globalData.navHeight =
          (a.statusBarHeight / a.screenWidth) * 750 + 90;
        this.globalData.rpxScreenHeight =
          (a.screenHeight / a.screenWidth) * 750;
        this.globalData.screenHeight = a.screenHeight;
        this.globalData.safeHeight = a.safeArea.bottom;
      } catch (a) {}
    },
    async getBaseInfo(vm, callBack) {
      const res = await vm.$u.api.getSettleBaseInfo();
      if (res.code !== 200) {
        return false;
      }

      vm.$u.vuex("vuex_settled", res.data || null);
      if (!res.data) {
        return;
      }
      if (typeof callBack == "function") {
        callBack(vm, res.data);
      }
      return res.data;
    },

    /**
     * 微信用户自动登录
     */
    async autoLogin() {
      let that = this;
	  // 如果token不为空,则跳过自动登录
      if(that.vuex_token) {
		return false
      }
	  await login.oauth().then(async (res) => {
        if (res.code) {
          let params = {
            code: res.code,
            wxAppNo: that.globalData.wxAppNo, // 自营平台小程序
          };
          let result = await that.$u.api.loginWechatAuth(params);
          if (result && result.code == 200 && result.data && result.data.token) {
            login.setUserData(result.data, this);
            this.profileSet(this)
            this.profileAppend(this)
          } else {
            uni.navigateTo({
              url: "pages/login/index",
            });
          }
        } else {
          uni.showModal({
            title: "登录失败",
            content: "未获取到code",
          });
        }
      });
    },

    /* 版本更新 */
    async updateApp(type) {
      if (uni.canIUse('getUpdateManager')) {
        // 版本更新
        const updateManager = uni.getUpdateManager();

        updateManager.onCheckForUpdate(function (res) {
          // 请求完新版本信息的回调
          if (!res.hasUpdate && type === 1) {
            uni.showModal({
              title: '提示',
              content: '当前版本已经是最新版本',
              showCancel: false
            })
          }
        });

        updateManager.onUpdateReady(function (res) {
          uni.showModal({
            title: "更新提示",
            content: "新版本已经准备好,是否重启应用?",
            success(res) {
              if (res.confirm) {
                // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                updateManager.applyUpdate()
              } else if (res.cancel) {
                //如果需要强制更新,则给出二次弹窗
                uni.showModal({
                  title: '温馨提示~',
                  content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦~',
                  showCancel: false,
                  success: function (result) {
                    if (result.confirm) updateManager.applyUpdate()
                  }
                })
              }
            },
          });
        });

        updateManager.onUpdateFailed(function (res) {
          // 新的版本下载失败
          uni.showModal({
            title: '已经有新版本了哟~',
            content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
            showCancel: false
          })
        });
      } else {
        uni.showModal({
          title: '提示',
          content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。',
          showCancel: false
        })
      }
    },

    /* ------------------------- 数据埋点begin ------------------------------ */
    track(event, properties) {
      if (AnalysysAgent) {
        // 易观添加事件
        let AnalysysAgent = wx.AnalysysAgent;
        AnalysysAgent.track("self_support_" + event, properties);
      }
    },
    profileSet(vm) {
      // 设备身份标识
      if (AnalysysAgent) {
        let user = vm.$u.deepClone(vm.vuex_user);
        let profile = vm.$u.deepClone(vm.vuex_auth_user);
        profile.openid = user.wxopenid || profile.openid
        profile.unionid = user.unionid || profile.unionid || null
        AnalysysAgent.profileSet(profile);
      }
    },
    profileAppend(vm) {
      if (AnalysysAgent) {
		    let user = vm.$u.deepClone(vm.vuex_user);
		    // 用户id设置
		    AnalysysAgent.alias(user.id + "");
        // 用户附加属性
		    let profile = {
			    userfrom: "自营平台",
			    id: user.id,
			    mobile: user.mobile,
			    loginName: user.loginName,
			    source: user.score,
        };
        Object.keys(profile).map((key) => {
          if (key && profile[key]) {
            AnalysysAgent.profileAppend(key, profile[key]);
          }
        });
      }
    },
    share(toShareProperties, trackProperties) {
      if (AnalysysAgent) {
        AnalysysAgent.share(toShareProperties, trackProperties);
      }
    },
    trackPage(pageName, properties) {
      if (AnalysysAgent) {
        AnalysysAgent.pageView(pageName, properties);
      }
    },
    initShare(option) {
      option = option || {};
      if (AnalysysAgent && option.user_id) {
        let shareUserInfo = {
          share_from_id: option.user_id || "",
          share_from_nickname: option.user_name || "",
        };
        AnalysysAgent.registerSuperProperties(shareUserInfo);
      }
    },
    /* ------------------------- 数据埋点end ------------------------------ */
  },
};
</script>

<style>
/*每个页面公共css */
@import "@/common/iconfont.css";
</style>
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
@import "@/common/index.scss";
</style>