Files
xdd-uniapp-new/main.js
T

148 lines
3.4 KiB
JavaScript

import Vue from 'vue'
import App from './App'
import global from "./assets/script/global";
import store from "./store";
import schema from "async-validator";
import dialog from "./utils/dialog";
import mixin from '@/mixins/share-mixins.js'
import {_router, parseRoute} from "@/utils";
import {
SERVICE_API_URL,
SOCKET_URL,
STATIC_RESOURCE_URL,
VUE_APP_API_URL,
VUE_APP_RESOURCES_URL,
WX_LIVE_APPID
} from "@/config";
import uView from "uview-ui";
import GooSkeleton from '@/components/GooSkeleton/index.vue'
import { pageToWatchData } from '@/config/page'
Vue.use(uView)
Vue.component('GooSkeleton', GooSkeleton)
Vue.mixin(mixin)
// 注册全局组件
Vue.config.productionTip = false;
Vue.config.devtools = process.env.NODE_ENV !== "production";
Vue.prototype.$SERVICE_API_URL = SERVICE_API_URL
Vue.prototype.$SOCKET_URL = SOCKET_URL
Vue.prototype.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL
Vue.prototype.$STATIC_RESOURCE_URL = STATIC_RESOURCE_URL
Vue.prototype.$VUE_APP_API_URL = VUE_APP_API_URL
Vue.prototype.$WX_LIVE_APPID = WX_LIVE_APPID
Vue.prototype.$global = global
Vue.prototype.$pageToWatchData = pageToWatchData
Vue.prototype.$validator = function (rule) {
return new schema(rule);
};
// const CACHE_KEY = "clear_0.0.1";
// if (!cookie.has(CACHE_KEY)) {
// cookie.clearAll();
// cookie.set(CACHE_KEY, 1);
// }
// 强制转为几位小数,不足的补0
const forceToDecimal = function changeToDecimal(value, len = 1) {
const f_x = parseFloat(value)
if (isNaN(f_x)) {
return 0
}
let s = f_x.toString()
let rs = s.indexOf('.')
if (rs < 0) {
rs = s.length
s += '.'
}
while (s.length <= rs + len) {
s += '0'
}
const tempArr = s.split('.')
const decimalArr = tempArr[1].split('')
let res = tempArr[0] + '.'
for (let i = 0; i < len; i++) {
res += decimalArr[i]
}
return res
}
// 强制转为2位小数,不足的补0
const force2Decimal = function change2Decimal(value) {
return forceToDecimal(value, 2)
}
const toast = (title = '', position = 'center', success = function() {}) => {
uni.showToast({
title,
mask: false,
icon: 'none',
duration: 2500,
position,
success
})
}
Vue.prototype.$force2Decimal = force2Decimal
Vue.prototype.$forceToDecimal = forceToDecimal
Vue.config.productionTip = false
App.mpType = 'app'
Vue.prototype.$store = store
Vue.prototype.$dialog = dialog
Vue.prototype.$toast = toast
const app = new Vue(App)
Vue.mixin({
onLoad() {
const {
$mp
} = this.$root
this._route = parseRoute($mp)
this._data.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL;
},
onShow() {
_router.app = this
_router.currentRoute = this._route
}
})
Object.defineProperty(Vue.prototype, '$yrouter', {
get() {
return _router
}
})
Object.defineProperty(Vue.prototype, '$yroute', {
get() {
return this._route
}
})
// #ifdef H5
// H5编译的代码
Vue.prototype.$deviceType = 'h5'
store.commit('updateDevicetype', 'h5')
// #endif
// #ifdef APP-PLUS
// App平台编译的代码
Vue.prototype.$deviceType = 'app'
store.commit('updateDevicetype', 'app')
Vue.prototype.$platform = uni.getSystemInfoSync().platform
// #endif
// #ifdef MP-WEIXIN
// 微信小程序编译的代码
Vue.prototype.$deviceType = 'routine'
store.commit('updateDevicetype', 'routine')
// #endif
app.$mount()