App.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <script>
  2. import { User } from "@/config/api.js";
  3. export default {
  4. onLaunch: function () {
  5. let result = wx.getLaunchOptionsSync();
  6. this.$store.commit("getSceneNumber", result.scene);
  7. if (result.scene != 1154) {
  8. !this.$db.get("access_token") && this.getOpenid();
  9. const ENV = uni.getAccountInfoSync().miniProgram;
  10. // #ifdef MP
  11. this.checkVersion();
  12. // #endif
  13. }
  14. },
  15. onHide: function () {},
  16. globalData: {
  17. isLogin: false,
  18. isAuth: null, //是否需要授权 uniid
  19. isBind: null, // 是否需要绑定手机号/邮箱
  20. userInfo: null, //用户信息
  21. access_token: "",
  22. loadOver: "",
  23. },
  24. methods: {
  25. /* 微信code换临时token */
  26. getOpenid() {
  27. uni.login({
  28. success: (result) => {
  29. User.wechatLog({
  30. Code: result.code,
  31. }).then((res) => {
  32. try {
  33. let token = res.Data.Authorization;
  34. this.$db.set("access_token", token);
  35. // this.$isResolve()
  36. } catch (e) {}
  37. });
  38. },
  39. });
  40. },
  41. checkVersion() {
  42. const updateManager = uni.getUpdateManager();
  43. updateManager.onCheckForUpdate(function (res) {
  44. // 请求完新版本信息的回调
  45. });
  46. updateManager.onUpdateReady(function (res) {
  47. uni.showModal({
  48. title: "更新提示",
  49. content: "新版本已经准备好,是否重启应用?",
  50. success(res) {
  51. if (res.confirm) {
  52. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  53. updateManager.applyUpdate();
  54. }
  55. },
  56. });
  57. });
  58. updateManager.onUpdateFailed(function (res) {
  59. // 新的版本下载失败
  60. });
  61. },
  62. },
  63. };
  64. </script>
  65. <style lang="scss">
  66. @import "uview-ui/index.scss";
  67. /* 页面公共样式 */
  68. @import "./style/common.scss";
  69. </style>