Files
zhgh_cpu/src/main/resources/static/assets/mobile/js/basic.js
T
2026-10-20 20:50:11 +08:00

244 lines
6.7 KiB
JavaScript

const uploadFileType = ['jpg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'pdf']
const docType = ['doc', 'docx', 'xls', 'xlsx', 'pdf']
const FILE_UPLOAD_ADDRESS = '/file_server/uploadFile'
const FILE_DELETE_ADDRESS = '/file_server/deleteFile'
const FILE_STREAM_PREVIEW_ADDRESS = '/file_server/fileStreamPreview'
Vue.component('m-page-loading', httpVueLoader('/components/mobile/common/MLoading.vue'))
Vue.component('m-table-loading', httpVueLoader('/components/mobile/common/MTableLoading.vue'))
Vue.component('m-card', httpVueLoader('/components/mobile/common/MCard.vue'))
Vue.component('vant-file-upload', httpVueLoader('/components/plugins/VantFileUpload.vue'))
const GetQueryString = (name) => {
const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
const r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return "";
}
const removeHTMLTag = (str) => {
str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
str = str.replace(/\n[\s| | ]*\r/g, '\n'); //去除多余空行
str = str.replace(/&nbsp;/ig, '');//去掉&nbsp;
return str;
}
const CREATE_PREVIEW_URL = (val) => {
return FILE_STREAM_PREVIEW_ADDRESS + "?id=" + val
}
const clone = (val) => {
return JSON.parse(JSON.stringify(val))
}
// H5 页面按需注册弹框同步回调;全站只保留一个 popstate 监听,弹框按后进先出关闭。
const mobilePopupHistory = {
owner: null,
token: null,
stack: [],
pending: null,
register(sync) {
this.owner = sync
this.token = String(Date.now()) + Math.random()
this.stack = []
return this
},
open(key) {
if (!this.owner || this.pending || this.stack.includes(key)) return
this.stack.push(key)
window.history.pushState(Object.assign({}, window.history.state, {
mobilePopupDepth: this.stack.length,
mobilePopupOwner: this.token
}), '', window.location.href)
this.owner(key, true)
},
// 返回 Promise,关闭确认框后再提交,避免回退尚未完成便清理父级弹框。
close() {
if (this.pending) return this.pending.promise
if (!this.stack.length) return Promise.resolve()
return this.back(1)
},
back(count) {
let complete
const promise = new Promise(resolve => { complete = resolve })
this.pending = {promise, complete}
window.history.go(-count)
return promise
},
clear() {
if (this.pending) return this.pending.promise.then(() => this.clear())
return this.stack.length ? this.back(this.stack.length) : Promise.resolve()
},
unregister(sync) {
if (this.owner !== sync) return
this.owner = null
this.stack = []
},
onPop(event) {
if (!this.owner) return
const depth = event.state && event.state.mobilePopupOwner === this.token
? event.state.mobilePopupDepth : 0
// 弹框回退由本管理器消费,避免 PJAX 同时将其识别为业务页面切换。
if (this.stack.length > depth || this.pending) event.stopImmediatePropagation()
while (this.stack.length > depth) {
this.owner(this.stack.pop(), false)
}
if (this.pending) {
const complete = this.pending.complete
this.pending = null
complete()
}
}
}
window.addEventListener('popstate', event => mobilePopupHistory.onPop(event), true)
const toChinesNum = (num) => {
let changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
let unit = ["", "十", "百", "千", "万"];
num = parseInt(num);
let getWan = (temp) => {
let strArr = temp.toString().split("").reverse();
let newNum = "";
for (let i = 0; i < strArr.length; i++) {
newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;
}
return newNum;
}
let overWan = Math.floor(num / 10000);
let noWan = num % 10000;
if (noWan.toString().length < 4) {
noWan = "0" + noWan;
}
return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
}
const loc = () => {
return location.href.replace(location.search, "").replace(location.hash, "")
}
const modal = {
// 消息提示
msg(content) {
vant.Toast(content)
},
// 错误消息
msgError(content) {
vant.Toast.fail(content)
},
// 成功消息
msgSuccess(content) {
vant.Toast.success(content)
},
// 弹出提示
alert(content) {
vant.Dialog.alert({
title: '提示',
message: content
}).then(() => {
// on close
});
},
// 确认窗体
confirm(content) {
return new Promise((resolve, reject) => {
vant.Dialog.confirm({
title: '提示',
message: content,
}).then(() => {
resolve()
}).catch(() => {
// reject()
})
})
},
// 提示信息
showToast(option) {
if (typeof option === "object") {
vant.Toast(option)
} else {
vant.Toast.loading({
message: option,
forbidClick: true,
loadingType: 'spinner',
duration: 2500
});
}
},
// 打开遮罩层
loading(content) {
vant.Toast.loading({
message: content,
forbidClick: true,
overlay: true,
duration: 0
});
},
// 关闭遮罩层
closeLoading() {
vant.Toast.clear();
}
}
Vue.prototype.$modal = modal
const nation = [
'汉族',
'蒙古族',
'回族',
'藏族',
'维吾尔族',
'苗族',
'彝族',
'壮族',
'布依族',
'朝鲜族',
'满族',
'侗族',
'瑶族',
'白族',
'土家族',
'哈尼族',
'哈萨克族',
'傣族',
'黎族',
'傈僳族',
'佤族',
'畲族',
'高山族',
'拉祜族',
'水族',
'东乡族',
'纳西族',
'景颇族',
'柯尔克孜族',
'土族',
'达翰尔族',
'么佬族',
'羌族',
'布朗族',
'撒拉族',
'毛南族',
'仡佬族',
'锡伯族',
'阿昌族',
'普米族',
'塔吉克族',
'怒族',
'乌孜别克族',
'俄罗斯族',
'鄂温克族',
'德昂族',
'保安族',
'裕固族',
'京族',
'塔塔尔族',
'独龙族',
'鄂伦春族',
'赫哲族',
'门巴族',
'珞巴族',
'基诺族'
];