App.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <script>
  2. import Global from './assets/http/global.js'
  3. export default {
  4. onLaunch: function() {
  5. //开启调试模式
  6. this.setEnableDebug()
  7. //更新版本
  8. this.updateApp()
  9. //获取token
  10. this.getToken()
  11. //获取小程序上下线
  12. // this.$u.vuex('vuex_audit',1)
  13. this.getAudit()
  14. },
  15. methods:{
  16. setEnableDebug(){
  17. uni.setEnableDebug({
  18. enableDebug: Global.enabledDebug
  19. })
  20. },
  21. getAudit(){
  22. let params={
  23. paramKey:'applet_audit'
  24. }
  25. this.$api.wxApp.appParams(params).then(res=>{
  26. if (this.$isNotEmpty(res.data)) {
  27. this.$u.vuex('vuex_audit',res.data.paramValue)
  28. }
  29. })
  30. },
  31. updateApp(){
  32. const updateManager = uni.getUpdateManager();
  33. updateManager.onCheckForUpdate(function (res) {
  34. // 请求完新版本信息的回调
  35. console.log("是否有新版本:",res.hasUpdate);
  36. });
  37. updateManager.onUpdateReady(function (res) {
  38. uni.showModal({
  39. title: '更新提示',
  40. content: '新版本已经准备好,是否重启应用?',
  41. success(res) {
  42. if (res.confirm) {
  43. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  44. updateManager.applyUpdate();
  45. }
  46. }
  47. });
  48. });
  49. updateManager.onUpdateFailed(function (res) {
  50. // 新的版本下载失败
  51. });
  52. },
  53. async getToken(){
  54. let token = uni.getStorageSync('token')
  55. let [, res] = await uni.request({
  56. url: Global.tokenUrl,
  57. method: 'POST',
  58. header: {
  59. Authorization: "Basic c2FiZXI6c2FiZXJfc2VjcmV0"
  60. },
  61. })
  62. //否则保存新的token
  63. token = res.data.token_type + " " + res.data.access_token
  64. uni.setStorageSync('token', token)
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss">
  70. @import "uview-ui/index.scss";
  71. @import "assets/colorui/main.css";
  72. @import "assets/colorui/icon.css";
  73. @import "assets/colorui/app.scss"; /* 你的项目css */
  74. </style>