123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- import Vue from 'vue'
- function setBar() {
- uni.getSystemInfo({
- success: function (e) {
- // #ifndef MP
- Vue.prototype.usePort = 'h5';
- Vue.prototype.StatusBar = e.statusBarHeight;
- if (e.platform == 'android') {
- Vue.prototype.CustomBar = e.statusBarHeight + 50;
- } else {
- Vue.prototype.CustomBar = e.statusBarHeight + 45;
- };
- // #endif
- // #ifdef MP-WEIXIN
- Vue.prototype.usePort = 'wechat';
- Vue.prototype.StatusBar = e.statusBarHeight;
- let custom = wx.getMenuButtonBoundingClientRect();
- Vue.prototype.Custom = custom;
- Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
- // #endif
- // #ifdef MP-ALIPAY
- Vue.prototype.StatusBar = e.statusBarHeight;
- Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
- // #endif
- }
- })
- }
- function setLink(systemclient = "marketingtool") {
- switch (systemclient) {
- case "demo":
- Vue.prototype.qrCodePrefix = "https://lsa.cnyunl.com/";
- break;
- case "marketingtool":
- Vue.prototype.qrCodePrefix = "https://www.jiushengboard.cc/";
- break;
- case "demo2":
- Vue.prototype.qrCodePrefix = "https://lsa.cnyunl.com/jindi/";
- break;
- }
- }
- function mount() {
- Vue.prototype.getLocation = (isHighAccuracy = false) => {
- return new Promise((resolve, reject) => {
- let that = this;
- handle()
- function handle() {
- uni.getLocation({
- isHighAccuracy,
- highAccuracyExpireTime: isHighAccuracy ? 8000 : '',
- success: res => {
- console.log("获取定位", res)
- resolve(res)
- },
- fail: err => {
- console.log("获取位置失败", err)
- uni.hideLoading();
- if (["getLocation:fail 系统错误,错误码:-13000,meet frequency limit, please slowdown and try again later", "getLocation:fail auth deny"].includes(err.errMsg)) return resolve();
- query()
- }
- })
- }
- function query() {
- uni.getSetting({
- success({
- authSetting
- }) {
- if (authSetting['scope.userLocation']) {
- handle()
- } else {
- uni.showModal({
- title: '提示',
- content: '需要获取您的地理位置,请确认授权,否则可能会定位门店不准确',
- cancelText: '下次再说',
- confirmText: '前去授权',
- success: ({
- confirm
- }) => {
- if (confirm) {
- uni.openSetting({
- success(res) {
- if (res.authSetting['scope.userLocation']) handle();
- }
- })
- } else {
- /* uni.showToast({
- title: "您未授权地理位置,",
- icon: "none",
- }) */
- resolve();
- }
- }
- })
- }
- }
- })
- }
- })
- };
- Vue.prototype.cutoff = (msg, title = "", mask = false, exitTime = 0, icon = 'none', duration = 2000, ) => {
- if (msg != '成功' || title) uni.showToast({
- title: msg == '成功' ? title : msg,
- duration,
- icon,
- mask: mask || exitTime != 0
- })
- if (exitTime && msg == '成功') setTimeout(uni.navigateBack, exitTime)
- return msg != '成功';
- };
- Vue.prototype.paging = (content, init, update) => {
- if (update) {
- let content1 = JSON.parse(JSON.stringify(content));
- content1.pageSize = (content1.pageNumber - 1) * content1.pageSize;
- content1.pageNumber = 1;
- return content1
- } else {
- if (content.pageTotal == undefined || !content.pageTotal) content.pageTotal = 1;
- if (content.pageNumber == undefined || !content.pageNumber) content.pageNumber = 1;
- if (content.pageSize == undefined || !content.pageSize) content.pageSize = 20;
- if (init) content.pageNumber = 1;
- return content.pageNumber > content.pageTotal;
- }
- }
- Vue.prototype.tovw = (num) => (num * 100 / 375).toFixed(3) + "vw";
- Vue.prototype.getCity = (obj, isAll = true) => obj.province + obj.city + obj.county + (isAll ? obj.address : '');
- Vue.prototype.getApps = (appRemark, route) => {
- const list = Object.values(uni.getStorageSync('authList')[appRemark])
- return route ? list.find(v => v.path == route || v.pathDetail == route) : list
- };
- Vue.prototype.getHeight = (even, that, calculate = true) => {
- return new Promise((resolve, reject) => {
- if (calculate) {
- uni.getSystemInfo({
- success(s) {
- uni.createSelectorQuery().in(that).select(even).boundingClientRect().exec(res => (!res[0]) ? reject('没有查询到元素') : resolve(s.windowHeight - res[0].bottom))
- }
- });
- } else {
- uni.createSelectorQuery().in(that).select(even).boundingClientRect().exec(res => (!res[0]) ? reject('没有查询到元素') : resolve(res[0]))
- }
- })
- };
- //compressed压缩图;thumbnail缩略图,hls转码视频,cover封面
- Vue.prototype.getSpecifiedImage = (item, type = 'thumbnail') => {
- if (!item) return "";
- let v = item.subfiles.find(v => v.type == type);
- return v ? v.url : item.url;
- }
- Vue.prototype.formatTime = (date = new Date(), j1 = '-', j2 = ':') => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : `0${n}`
- }
- return `${[year, month, day].map(formatNumber).join(j1)} ${[hour, minute, second].map(formatNumber).join(j2)}`
- }
- Vue.prototype.getCustomClass = (typename) => {
- return new Promise((resolve, reject) => {
- Vue.prototype.$Http.basic({
- "classname": "sysmanage.develop.optiontype.optiontype",
- "method": "optiontypeselect",
- "content": {
- typename
- }
- }).then(res => {
- console.log("获取自定义分类" + typename, res)
- if (res.msg != '成功') return resolve([]);
- resolve(res.data);
- })
- })
- }
- Vue.prototype.CNY = (sum, symbol = '¥', strict = true, precision = 2) => {
- const currency = require("./currency.js");
- let num = currency(sum, {
- symbol,
- precision
- }).format();
- if (strict) {
- let decimals = num.split(".");
- decimals[1] = ('0.' + decimals[1] - 0 + '').substring(2)
- num = decimals[1] ? decimals.join(".") : decimals[0]
- }
- return num
- }
- Vue.prototype.callPhone = phoneNumber => {
- uni.makePhoneCall({
- phoneNumber: phoneNumber + '',
- complete: res => {
- console.log('makePhoneCall', res)
- }
- })
- }
- Vue.prototype.dye = (list, colors, num = 2) => {
- let count = num - 1,
- index = 0;
- return list.map((v, i) => {
- if (i > count) {
- count += num;
- index += 1;
- }
- v.color = colors[index % colors.length]
- return v
- })
- }
- Vue.prototype.getReg = name => {
- let obj = {
- phonenumber: {
- reg: '^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\\d{8}$',
- errText: "请输入正确的11位手机号码!"
- },
- email: {
- reg: '^([A-Za-z0-9_\\-\\.])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})$',
- errText: "请输入正确的邮箱格式!"
- }
- }
- return obj[name] || ''
- }
- Vue.prototype.daysAgo = num => {
- let now = new Date().getTime() - 0,
- end = now + 86400000,
- beg = end - (num * 86400000);
- return {
- begindate: Vue.prototype.formatTime(new Date(beg)).split(' ')[0],
- enddate: Vue.prototype.formatTime(new Date(end)).split(' ')[0],
- }
- }
- Vue.prototype.getUrlParams = urlStr => {
- const url = decodeURIComponent(urlStr)
- let obj = {}
- let str = url.slice(url.indexOf('?') + 1),
- arr = str.split('&');
- obj.funName = url.slice(0, url.indexOf('?')).split("/").pop();
- for (let j = arr.length, i = 0; i < j; i++) {
- let arr_temp = arr[i].split('=')
- obj[arr_temp[0]] = arr_temp[1]
- }
- return obj
- }
- Vue.prototype.switchPage = app => {
- if (app.path) {
- uni.navigateTo({
- url: app.path,
- fail: (fail) => {
- console.log("跳转失败原因", fail)
- }
- })
- } else {
- if (app.name == 'index_design') {
- app.name = 'design';
- } else if (['index_6C', 'index_freeDesign'].includes(app.name)) {
- app.name = 'longText';
- };
- if (app.name == 'index_design') app.name = 'design';
- switch (app.name) {
- case 'design':
- Vue.prototype.$Http.changePage("index", "案例", {
- active: '实景案例'
- })
- break;
- case 'index_product':
- Vue.prototype.$Http.changePage("cloud", "单品")
- break;
- case 'index_commodity':
- Vue.prototype.$Http.changePage("index", "活动")
- break;
- case 'index_imgs':
- Vue.prototype.$Http.changePage("index", "案例", {
- active: '图库'
- })
- break;
- case 'index_dataBank':
- Vue.prototype.$Http.changePage("cloud", "资料库")
- break;
- case 'index_school':
- Vue.prototype.$Http.changePage("cloud", "商学院")
- break;
- case 'index_video':
- Vue.prototype.$Http.changePage("index", "视频")
- break;
- case 'index_cloud':
- Vue.prototype.$Http.changePage("cloud", "工作台")
- break;
- case 'longText':
- if (app.forms.path) {
- uni.navigateTo({
- url: app.forms.path.formcols[0].title
- })
- } else {
- console.log("长图文", app)
- }
- break;
- default:
- console.log("未配置路径", app.name)
- break;
- }
- }
- console.log(app);
- }
- Vue.prototype.isInitializeLogin = (fun) => {
- const systemInitIsComplete = getApp().globalData.systemInitIsComplete;
- if (!systemInitIsComplete || typeof systemInitIsComplete == 'object') {
- getApp().globalData.HomePageStartRendering.push(fun)
- } else {
- fun()
- }
- }
- }
- module.exports = {
- mount,
- setBar,
- setLink
- }
|