Yizhan-app/main.js

198 lines
5.4 KiB
JavaScript
Raw Normal View History

2025-01-22 16:03:17 +08:00
import Vue from 'vue'
import store from './store'
import App from './App'
import apis from '@/common/vmeitime-http/'
import Json from './Json' //测试用数据
import Vant from 'vant';
import 'vant/lib/index.less';
import $ from '@/jquery-2.2.4.min.js';
import {
devEnv,
} from '@/common/util.js';
Vue.prototype.$imgUrl = '@static/loadingMf.gif'
Vue.use(Vant);
import btn from '@/common/buttonPermission.js'
Vue.directive('btn', btn)
let timeout = null
let debounce = function(fn, wait) {
if (timeout !== null) clearTimeout(timeout)
timeout = setTimeout(fn, wait)
}
Vue.prototype.debounce = debounce
Vue.prototype.$ = $;
let roleList = uni.getStorageSync('roles') || ''
Vue.prototype.roleList = roleList
Vue.prototype.parseTime = function parseTime(time, pattern) {
if (arguments.length === 0 || !time) {
return null
}
const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'object') {
date = time
} else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
} else if (typeof time === 'string') {
time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.\d{3}/gm), '');
}
if ((typeof time === 'number') && (time.toString().length === 10)) {
time = time * 1000
}
date = new Date(time)
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
}
const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
let value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value]
}
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
}
/**
* 因工具函数属于公司资产, 所以直接在Vue实例挂载几个常用的函数
* 所有测试用数据均存放于根目录json.js
*
* css部分使用了App.vue下的全局样式和iconfont图标有需要图标库的可以留言
* 示例使用了uni.scss下的变量, 除变量外已尽量移除特有语法,可直接替换为其它预处理器使用
*/
// #ifdef H5
// 提交前需要注释 本地调试使用
let vconShow = uni.getStorageSync('1003080_vconShow') == null ? '0' : uni.getStorageSync('1003080_vconShow');
if (vconShow != 0) {
const vconsole = require('vconsole')
Vue.prototype.$vconsole = new vconsole() // 使用vconsole
}
// #endif
// if (/(Android)/i.test(navigator.userAgent)) {
// Vue.prototype.wxSdk=jWeixin;
// }
// if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
// Vue.prototype.wxSdk=wx;
// }
const msg = (title, duration = 2500, mask = false, icon = 'none') => {
//统一提示方便全局修改
if (Boolean(title) === false) {
return;
}
uni.showToast({
title,
duration,
mask,
icon
});
}
const json = type => {
//模拟异步请求数据
return new Promise(resolve => {
setTimeout(() => {
resolve(Json[type]);
}, 500)
})
}
const prePage = () => {
let pages = getCurrentPages();
let prePage = pages[pages.length - 2];
// #ifdef H5
return prePage;
// #endif
return prePage.$vm;
}
const formatter = (value) => {
if (/\D/.test(value)) return `${value}`;
if (value >= 10000) return `${(value / 10000).toFixed(2)}`;
return `${value}`;
}
Vue.prototype.replaceImgUrls = (url) => {
let replacedUrl = ''
if (!devEnv) {
const originalUrl = url.replace('webImageDir', 'appImageDir');
const newIpAddress = '127.0.0.1';
const newPort = uni.getStorageSync("ZHHQ_HLJ_PORT");
replacedUrl = originalUrl.replace(/\/\/([\d]+\.[\d]+\.[\d]+\.[\d]+):(\d+)/,
`//${newIpAddress}:${newPort}`);
} else {
replacedUrl = url
}
return replacedUrl
}
const serviceUrl = "http://localhost:8080/";
Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
Vue.prototype.$api = {
msg,
json,
prePage,
formatter,
serviceUrl
};
App.mpType = 'app'
Vue.prototype.$apis = apis
// 开发模式
Vue.prototype.ISDEV = false
/* let jweixin = require('ts-jwsdk') ;
Vue.prototype.$wx = jweixin; */
const app = new Vue({
...App
})
app.$mount()
//记录选择图片备份
// wx.chooseImage({
// count: 3, // 默认9
// sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
// sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
// quality: 0.7, //压缩质量范围01数值越小质量越低压缩率越高仅对jpg有效
// success: function (res) {
// let localIds = res.localIds; // 返回选定照片的本地ID列表
// if(typeof localIds=='string'){
// wxSdk.getLocalImgData({
// localId: localIds, // 图片的localID
// success: function (res) {
// var localData = res.localData; // localData是图片的base64数据可以用img标签显示
// if(_this.imgs.length<3){
// _this.imgs.push(localData);
// }
// }
// });
// }else{
// for(var i=0;i<localIds.length;i++){
// wxSdk.getLocalImgData({
// localId: localIds[i], // 图片的localID
// success: function (res) {
// var localData = res.localData; // localData是图片的base64数据可以用img标签显示
// if(_this.imgs.length<3){
// _this.imgs.push(localData);
// }
// }
// });
// }
// }
// }
// });