Sfoglia il codice sorgente

$platform改为platform

萤火科技 4 anni fa
parent
commit
0d10e5c6af
6 ha cambiato i file con 47 aggiunte e 14 eliminazioni
  1. 3 3
      core/app.js
  2. 35 0
      core/mixins/app.js
  3. 5 5
      main.js
  4. 1 1
      pages/checkout/index.vue
  5. 1 1
      pages/login/index.vue
  6. 2 4
      pages/user/index.vue

+ 3 - 3
core/app.js

@@ -34,12 +34,12 @@ export const showError = (msg, callback) => {
 /**
  * 显示纯文字提示框
  */
-export const showToast = (msg, duration = 1500) => {
+export const showToast = (msg, duration = 1500, mask = true) => {
   uni.showToast({
     title: msg, // 提示的内容
     icon: 'none',
-    mask: true, // 是否显示透明蒙层,防止触摸穿透
-    duration // 提示的延迟时间,单位毫秒,默认:1500	
+    mask, // 是否显示透明蒙层,防止触摸穿透
+    duration // 提示的延迟时间,单位毫秒,默认:1500  
   })
 }
 

+ 35 - 0
core/mixins/app.js

@@ -0,0 +1,35 @@
+import Vue from 'vue'
+import { mapGetters } from 'vuex'
+import store from '@/store/index'
+import platform from '@/core/platform'
+
+// 字符串驼峰转中划线
+const formatToLine = value => {
+  return value.replace(/([A-Z])/g, '-$1').toLowerCase()
+}
+
+// 主题样式 (因小程序端不支持styleObject语法,所以需要转换成字符串)
+const appTheme2Str = appTheme => {
+  let str = ''
+  for (const index in appTheme) {
+    const name = formatToLine(index)
+    str += `--${name}:${appTheme[index]};`
+  }
+  return str
+}
+
+export default {
+  data() {
+    return {
+      platform
+    }
+  },
+  computed: {
+    ...mapGetters(['appTheme']),
+    appThemeStyle() {
+      const appTheme = store.getters.appTheme
+      return appTheme2Str(appTheme)
+    }
+  }
+
+}

+ 5 - 5
main.js

@@ -2,8 +2,9 @@ import Vue from 'vue'
 import uView from 'uview-ui'
 import App from './App'
 import store from './store'
-import platform from './core/platform'
 import bootstrap from './core/bootstrap'
+import mixin from './core/mixins/app'
+import './js_sdk/ican-H5Api/ican-H5Api'
 import {
   navTo,
   showToast,
@@ -11,18 +12,17 @@ import {
   showError,
   getShareUrlParams
 } from './core/app'
-import './js_sdk/ican-H5Api/ican-H5Api'
 
 Vue.config.productionTip = false
 
 App.mpType = 'app'
 
-// 当前运行的终端
-Vue.prototype.$platform = platform
-
 // 载入uView库
 Vue.use(uView)
 
+// 全局mixin
+Vue.mixin(mixin)
+
 // 挂载全局函数
 Vue.prototype.$toast = showToast
 Vue.prototype.$success = showSuccess

+ 1 - 1
pages/checkout/index.vue

@@ -340,7 +340,7 @@
         // 如果只有一种配送方式则不显示选项卡
         app.isShowTab = setting.deliveryType.length > 1
         // 当前选择支付方式 (如果是微信小程序默认使用微信支付)
-        if (app.$platform === 'MP-WEIXIN') {
+        if (app.platform === 'MP-WEIXIN') {
           app.curPayType = PayTypeEnum.WECHAT.value
         }
       },

+ 1 - 1
pages/login/index.vue

@@ -53,7 +53,7 @@
         console.log('setShowUserInfo start')
         const app = this
         // 判断当前客户端是微信小程序, 并且支持getUserProfile接口
-        const isMpWeixin = app.$platform === 'MP-WEIXIN' && wx.canIUse('getUserProfile')
+        const isMpWeixin = app.platform === 'MP-WEIXIN' && wx.canIUse('getUserProfile')
 
         // 获取后台设置
         await SettingModel.item(SettingKeyEnum.REGISTER.value, false)

+ 2 - 4
pages/user/index.vue

@@ -1,7 +1,7 @@
 <template>
   <view v-if="!isFirstload" class="container">
     <!-- 页面头部 -->
-    <view class="main-header" :style="{ height: $platform == 'H5' ? '240rpx' : '280rpx', paddingTop: $platform == 'H5' ? '0' : '80rpx' }">
+    <view class="main-header" :style="{ height: platform == 'H5' ? '260rpx' : '320rpx', paddingTop: platform == 'H5' ? '0' : '80rpx' }">
       <image class="bg-image" src="/static/background/user-header2.png" mode="scaleToFill"></image>
       <!-- 用户信息 -->
       <view v-if="isLogin" class="user-info">
@@ -107,7 +107,7 @@
               <text v-else class="text">99+</text>
             </view>
           </view>
-          <view v-if="item.type == 'button' && $platform == 'MP-WEIXIN'" class="service-item">
+          <view v-if="item.type == 'button' && platform == 'MP-WEIXIN'" class="service-item">
             <button class="btn-normal" :open-type="item.openType">
               <view class="item-icon">
                 <text class="iconfont" :class="[`icon-${item.icon}`]"></text>
@@ -169,8 +169,6 @@
       return {
         // 枚举类
         SettingKeyEnum,
-        // 当前运行的终端 (此处并不冗余,因为微信小程序端view层无法直接读取$platform)
-        $platform: this.$platform,
         // 正在加载
         isLoading: true,
         // 首次加载