App.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <script>
  2. import store from '@/store'
  3. import { mapActions } from 'vuex'
  4. //import { setTimeout } from 'timers'
  5. import { getDictionaries } from '@/api/mini'
  6. import util from "./utils/util"
  7. import priceSocket from "./mixins/priceSocket";
  8. import permissionListener from "@/uni_modules/c-permission-listener"; //https://ext.dcloud.net.cn/plugin?id=22675
  9. export default {
  10. mixins:[priceSocket],
  11. // 全端,数据共享,还可以解决页面初始化模板访问不到值得
  12. // 有坑 分包里的页面访问不到
  13. globalData: {},
  14. onLaunch () {
  15. uni.removeStorageSync('suitInfoList');
  16. uni.removeStorageSync('productInfoList');
  17. uni.removeStorageSync('pxClassInfoList');
  18. // #ifdef APP-PLUS
  19. // 清除角标数字
  20. plus.runtime.setBadgeNumber(0);
  21. // #endif
  22. // 推送消息监听改在登录成功后注册,见 utils/appDevice.js setupAppPushMessageListener
  23. // #ifdef H5
  24. // H5 开发环境无微信授权:仅补齐 account;不再写入过期硬编码 token(会覆盖登录态并触发 /console/init 500)
  25. // 有本地 token 时拉取字典;必须 catch,否则 reject 的普通对象会被 webpack overlay 显示成 [object Object]
  26. if (process.env.NODE_ENV == "development") {
  27. if (!uni.getStorageSync('account')) {
  28. uni.setStorageSync("account", "0")
  29. }
  30. let h5Token = uni.getStorageSync('token')
  31. // 清理历史硬编码/已过期 JWT,避免每次启动都打出 500 并干扰登录态
  32. if (h5Token) {
  33. try {
  34. const payload = JSON.parse(atob(h5Token.split('.')[1] || ''))
  35. if (payload.exp && payload.exp * 1000 < Date.now()) {
  36. uni.removeStorageSync('token')
  37. h5Token = ''
  38. }
  39. } catch (e) {
  40. // 非 JWT 结构时保留原 token,交由接口鉴权
  41. }
  42. }
  43. if (h5Token) {
  44. getDictionaries({ token: h5Token }).then(res => {
  45. if (util.isEmpty(res)) {
  46. return false
  47. }
  48. store.commit('setDictionariesInfo', {
  49. ...res.data.dict,
  50. ...res.data
  51. })
  52. store.commit('setMyShopInfo', {
  53. ...res.data.shop,
  54. ...res.data
  55. })
  56. }).catch(err => {
  57. console.error('H5 拉取字典失败(token 可能失效,请重新登录)', err && (err.errMsg || err.msg || err.statusCode) || err)
  58. })
  59. }
  60. }
  61. // #endif
  62. // 删除缓存
  63. if (process.env.NODE_ENV == 'production') {
  64. uni.removeStorageSync('shopUser')
  65. }
  66. // #ifdef MP-WEIXIN
  67. // wxLoginFn()
  68. // uni.clearStorage()
  69. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  70. uni.setStorageSync('account', extConfig.account)
  71. // #endif
  72. },
  73. onLoad () {
  74. // const pages = getCurrentPages();
  75. // const currentPage = pages[pages.length - 1];
  76. // const url = `/${currentPage.route}`;
  77. // console.log(1111,url)
  78. },
  79. onShow (extraData) {
  80. // #ifdef APP-PLUS
  81. // 清除角标数字
  82. plus.runtime.setBadgeNumber(0);
  83. // #endif
  84. if(extraData){
  85. uni.setStorageSync('extraData',extraData)
  86. }
  87. // permissionEnums枚举建议单独一个js文件,然后引入
  88. const permissionEnums = {
  89. "ACCESS_COARSE_LOCATION": {
  90. name: "定位",
  91. explain: "在您主动使用注册填址、查找附近批发店、订单导航等功能时获取位置,用于匹配地址或打开地图"
  92. },
  93. "ACCESS_FINE_LOCATION": {
  94. name: "定位",
  95. explain: "在您主动使用注册填址、查找附近批发店、订单导航等功能时获取位置,用于匹配地址或打开地图"
  96. },
  97. "CALL_PHONE": {
  98. name: "电话", // 当前权限的名称
  99. explain: "为了方便联系客服, 我们需要申请您设备的拨打电话权限" // 权限说明
  100. },
  101. "CAMERA":{
  102. name:"使用摄像头",
  103. explain: "为了方便给花材拍照片,上传花材图片等"
  104. },
  105. "READ_EXTERNAL_STORAGE":{
  106. name:"读取外部存储空间",
  107. explain:"为了修改个人头像和上传花材图片, 我们需要申请您设备的相机和存储权限",
  108. },
  109. "WRITE_EXTERNAL_STORAGE":{
  110. name:"写入外部存储空间",
  111. explain:"为了保存推广海报和小程序码到手机相册, 我们需要申请您设备的存储权限",
  112. },
  113. "READ_MEDIA_IMAGES":{
  114. name:"读取外部存储空间",
  115. explain:"为了修改个人头像和上传花材图片, 我们需要申请您设备的相机和存储权限",
  116. },
  117. "READ_MEDIA_VIDEO":{
  118. name:"读取外部存储空间",
  119. explain:"为了修改个人头像和上传花材图片, 我们需要申请您设备的相机和存储权限",
  120. },
  121. "READ_MEDIA_AUDIO":{
  122. name:"读取外部存储空间",
  123. explain:"为了修改个人头像和上传花材图片, 我们需要申请您设备的相机和存储权限",
  124. },
  125. "POST_NOTIFICATIONS":{
  126. name:"通知",
  127. explain:"为了及时接收订单等重要消息,我们需要申请通知权限",
  128. },
  129. }
  130. // 唤起权限会触发onHide,所以listenerFunc须在onShow生命周期调用
  131. permissionListener && permissionListener.listenerFunc(permissionEnums)
  132. },
  133. onHide () { },
  134. onError (err) {
  135. console.error(err, '错误捕获')
  136. },
  137. methods: {
  138. ...mapActions(['setUserShopAll'])
  139. }
  140. }
  141. </script>
  142. <style lang="scss">
  143. //没有scss变量方法的,主要引入 这样打包的时候就不会所有的组件都打包进去
  144. @import "./static/iconfont/iconfont.css";
  145. @import "./static/css/uni2.css";
  146. @import "./static/css/base.scss";
  147. @import "./static/css/common.scss";
  148. @import "./static/css/reset.scss";
  149. page {
  150. height: 100%;
  151. }
  152. /**开单-扎和支切换样式**/
  153. .switchover-unit{
  154. position: fixed;
  155. left: calc(170upx / 2 - 50upx);
  156. bottom: 140upx;
  157. display: flex;
  158. align-items: center;
  159. justify-content: center;
  160. width: 100upx;
  161. height: 100upx;
  162. color: #FFFFFF;
  163. background: #4b8cf4;
  164. border-radius: 50%;
  165. font-size: 42upx;
  166. font-weight: 700;
  167. z-index: 2;
  168. }
  169. /**开单-增加减少动画**/
  170. .animation{animation:imgmove 0.3s 1;animation-iteration-count:1}
  171. @-webkit-keyframes imgmove{0%{transform: scale(0.7);}100%{transform: scale(1);}}
  172. </style>