App.vue 2.2 KB

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