mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 00:45:55 +08:00
更新
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
const TokenKey = 'Admin-Token'
|
||||
const UserId = 'userId'
|
||||
|
||||
export function getToken() {
|
||||
return Cookies.get(TokenKey)
|
||||
@@ -13,3 +14,15 @@ export function setToken(token) {
|
||||
export function removeToken() {
|
||||
return Cookies.remove(TokenKey)
|
||||
}
|
||||
|
||||
export function getUserId() {
|
||||
return Cookies.get(UserId)
|
||||
}
|
||||
|
||||
export function setUserId(userId) {
|
||||
return Cookies.set(UserId, userId)
|
||||
}
|
||||
|
||||
export function removeUserId() {
|
||||
return Cookies.remove(UserId)
|
||||
}
|
||||
|
||||
5
vue/src/utils/busEvent.js
Normal file
5
vue/src/utils/busEvent.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
const busEvent = new Vue()
|
||||
|
||||
export default busEvent
|
||||
@@ -11,7 +11,7 @@ import DictOptions from './DictOptions'
|
||||
export default class DictMeta {
|
||||
constructor(options) {
|
||||
this.type = options.type
|
||||
this.request = options.request,
|
||||
this.request = options.request
|
||||
this.responseConverter = options.responseConverter
|
||||
this.labelField = options.labelField
|
||||
this.valueField = options.valueField
|
||||
|
||||
29
vue/src/utils/generator/drawingDefault.js
Normal file
29
vue/src/utils/generator/drawingDefault.js
Normal file
@@ -0,0 +1,29 @@
|
||||
export default [
|
||||
{
|
||||
layout: 'colFormItem',
|
||||
tagIcon: 'input',
|
||||
label: '手机号',
|
||||
vModel: 'mobile',
|
||||
formId: 6,
|
||||
tag: 'el-input',
|
||||
placeholder: '请输入手机号',
|
||||
defaultValue: '',
|
||||
span: 24,
|
||||
style: { width: '100%' },
|
||||
clearable: true,
|
||||
prepend: '',
|
||||
append: '',
|
||||
'prefix-icon': 'el-icon-mobile',
|
||||
'suffix-icon': '',
|
||||
maxlength: 11,
|
||||
'show-word-limit': true,
|
||||
readonly: false,
|
||||
disabled: false,
|
||||
required: true,
|
||||
changeTag: true,
|
||||
regList: [{
|
||||
pattern: '/^1(3|4|5|7|8|9)\\d{9}$/',
|
||||
message: '手机号格式错误'
|
||||
}]
|
||||
}
|
||||
]
|
||||
@@ -5,11 +5,11 @@ let confGlobal
|
||||
let someSpanIsNot24
|
||||
|
||||
export function dialogWrapper(str) {
|
||||
return `<el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" title="Dialog Titile">
|
||||
return `<el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" title="Dialog Title">
|
||||
${str}
|
||||
<div slot="footer">
|
||||
<el-button @click="close">取消</el-button>
|
||||
<el-button type="primary" @click="handelConfirm">确定</el-button>
|
||||
<el-button type="primary" @click="handleConfirm">确定</el-button>
|
||||
</div>
|
||||
</el-dialog>`
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ function mixinMethod(type) {
|
||||
close: `close() {
|
||||
this.$emit('update:visible', false)
|
||||
},`,
|
||||
handelConfirm: `handelConfirm() {
|
||||
handleConfirm: `handleConfirm() {
|
||||
this.$refs['${confGlobal.formRef}'].validate(valid => {
|
||||
if(!valid) return
|
||||
this.close()
|
||||
|
||||
@@ -387,4 +387,39 @@ export function camelCase(str) {
|
||||
export function isNumberStr(str) {
|
||||
return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @desc 时间戳转日期毫秒
|
||||
* @param {String} format 时间格式 Y:年,M:月,D:天 h:小时,m:分钟,s:秒 默认:'Y/M/D h:m'
|
||||
*/
|
||||
export function formatDate2 (arg, format) {
|
||||
// console.log(typeof arg.toString());
|
||||
let now
|
||||
if (!arg) {
|
||||
return null
|
||||
} else {
|
||||
now = new Date(arg)
|
||||
}
|
||||
format = format || 'Y.M.D h:m'
|
||||
|
||||
const year = now.getFullYear()
|
||||
let month = now.getMonth() + 1
|
||||
month = month >= 10 ? month : '0' + month
|
||||
let date = now.getDate()
|
||||
date = date >= 10 ? date : '0' + date
|
||||
let hour = now.getHours()
|
||||
hour = hour >= 10 ? hour : '0' + hour
|
||||
let minute = now.getMinutes()
|
||||
|
||||
minute = minute >= 10 ? minute : '0' + minute
|
||||
let second = now.getSeconds()
|
||||
second = second >= 10 ? second : '0' + second
|
||||
return format
|
||||
.replace('Y', year)
|
||||
.replace('M', month)
|
||||
.replace('D', date)
|
||||
.replace('h', hour)
|
||||
.replace('m', minute)
|
||||
.replace('s', second)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export function loadBMap() {
|
||||
let script = document.createElement('script')
|
||||
script.type = 'text/javascript'
|
||||
script.src =
|
||||
'http://api.map.baidu.com/api?v=2.0&ak='+ process.env.VUE_APP_BAI_DU_AK +'&__ec_v__=20190126&callback=onBMapCallback'
|
||||
'http://api.map.baidu.com/api?v=2.0&ak='+ process.env.VUE_APP_BAI_DU_AK +'&s=1&__ec_v__=20190126&callback=onBMapCallback'
|
||||
script.onerror = reject
|
||||
document.head.appendChild(script)
|
||||
})
|
||||
|
||||
@@ -1,124 +1,132 @@
|
||||
import mqtt from 'mqtt'
|
||||
import { getToken } from "@/utils/auth";
|
||||
import mqtt from 'mqtt';
|
||||
import { getToken } from '@/utils/auth';
|
||||
|
||||
let mqttTool = {
|
||||
client: null,
|
||||
}
|
||||
};
|
||||
|
||||
/** 连接Mqtt */
|
||||
mqttTool.connect = function () {
|
||||
let options = {
|
||||
username: "wumei-smart",
|
||||
username: 'FastBee',
|
||||
password: getToken(),
|
||||
cleanSession: true,
|
||||
keepAlive: 30,
|
||||
clientId: 'web-' + Math.random().toString(16).substr(2),
|
||||
connectTimeout: 10000
|
||||
}
|
||||
connectTimeout: 60000,
|
||||
};
|
||||
// 配置Mqtt地址
|
||||
let url = process.env.VUE_APP_EMQX_SERVER_URL;
|
||||
let url = process.env.VUE_APP_MQTT_SERVER_URL;
|
||||
if (url == '') {
|
||||
url = "ws://" + window.location.hostname + ":8083/mqtt";
|
||||
console.log('自动获取地址');
|
||||
console.log('自动获取mqtt连接地址');
|
||||
if (window.location.protocol === 'http:') {
|
||||
url = 'ws://' + window.location.hostname + ':8083/mqtt';
|
||||
} else {
|
||||
url = 'wss://' + window.location.hostname + '/mqtt';
|
||||
}
|
||||
}
|
||||
console.log("mqtt地址:", url);
|
||||
console.log('mqtt地址:', url);
|
||||
mqttTool.client = mqtt.connect(url, options);
|
||||
mqttTool.client.on("connect", (e) => {
|
||||
mqttTool.client.on('connect', (e) => {
|
||||
console.log('mqtt连接成功');
|
||||
});
|
||||
// 重新连接
|
||||
mqttTool.client.on('reconnect', (error) => {
|
||||
console.log('正在重连:', error)
|
||||
console.log('正在重连:', error);
|
||||
});
|
||||
// 发生错误
|
||||
mqttTool.client.on('error', (error) => {
|
||||
console.log('Mqtt客户端连接失败:', error)
|
||||
console.log('Mqtt客户端连接失败:', error);
|
||||
mqttTool.client.end();
|
||||
})
|
||||
});
|
||||
// 断开连接
|
||||
mqttTool.client.on('close', function (res) {
|
||||
console.log('已断开Mqtt连接');
|
||||
});
|
||||
}
|
||||
};
|
||||
/** 断开连接 */
|
||||
mqttTool.end = function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (mqttTool.client == null) {
|
||||
resolve('未连接')
|
||||
console.log("未连接")
|
||||
resolve('未连接');
|
||||
console.log('未连接');
|
||||
return;
|
||||
}
|
||||
mqttTool.client.end()
|
||||
mqttTool.client = null
|
||||
mqttTool.client.end();
|
||||
mqttTool.client = null;
|
||||
console.log('Mqtt服务器已断开连接!');
|
||||
resolve('连接终止')
|
||||
})
|
||||
}
|
||||
resolve('连接终止');
|
||||
});
|
||||
};
|
||||
/** 重新连接 */
|
||||
mqttTool.reconnect = function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (mqttTool.client == null) {
|
||||
// 调用resolve方法,Promise变为操作成功状态(fulfilled)
|
||||
resolve('未连接')
|
||||
console.log("未连接")
|
||||
resolve('未连接');
|
||||
console.log('未连接');
|
||||
return;
|
||||
}
|
||||
console.log('正在重连...', res);
|
||||
mqttTool.client.reconnect()
|
||||
})
|
||||
}
|
||||
mqttTool.client.reconnect();
|
||||
});
|
||||
};
|
||||
/** 消息订阅 */
|
||||
mqttTool.subscribe = function (topics) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (mqttTool.client == null) {
|
||||
resolve('未连接')
|
||||
console.log("未连接")
|
||||
resolve('未连接');
|
||||
console.log('未连接');
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: 'mqtt未连接',
|
||||
});
|
||||
return;
|
||||
}
|
||||
mqttTool.client.subscribe(topics, {
|
||||
qos: 1
|
||||
}, function (err, res) {
|
||||
console.log("订阅主题:", topics);
|
||||
if (!err) {
|
||||
console.log("订阅成功")
|
||||
resolve('订阅成功')
|
||||
} else {
|
||||
console.log("订阅失败,主题可能已经订阅")
|
||||
resolve('订阅失败')
|
||||
return;
|
||||
mqttTool.client.subscribe(
|
||||
topics,
|
||||
{
|
||||
qos: 1,
|
||||
},
|
||||
function (err, res) {
|
||||
console.log('订阅主题:', topics);
|
||||
if (!err) {
|
||||
console.log('订阅成功');
|
||||
resolve('订阅成功');
|
||||
} else {
|
||||
console.log('订阅失败,主题可能已经订阅');
|
||||
resolve('订阅失败');
|
||||
return;
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
/** 取消订阅 */
|
||||
mqttTool.unsubscribe = function (topics) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (mqttTool.client == null) {
|
||||
resolve('未连接')
|
||||
console.log("未连接")
|
||||
resolve('未连接');
|
||||
console.log('未连接');
|
||||
return;
|
||||
}
|
||||
mqttTool.client.unsubscribe(topics, function (err) {
|
||||
if (!err) {
|
||||
resolve('取消订阅成功')
|
||||
console.log("取消订阅成功")
|
||||
resolve('取消订阅成功');
|
||||
console.log('取消订阅成功');
|
||||
} else {
|
||||
resolve('取消订阅失败')
|
||||
console.log("取消订阅失败")
|
||||
resolve('取消订阅失败');
|
||||
console.log('取消订阅失败');
|
||||
return;
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
mqttTool.publish = function (topic, message, name) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (mqttTool.client == null) {
|
||||
resolve('Mqtt客户端未连接')
|
||||
console.log("Mqtt客户端未连接")
|
||||
resolve('Mqtt客户端未连接');
|
||||
console.log('Mqtt客户端未连接');
|
||||
return;
|
||||
}
|
||||
mqttTool.client.publish(topic, message, { qos: 1 }, function (err) {
|
||||
@@ -126,19 +134,19 @@ mqttTool.publish = function (topic, message, name) {
|
||||
console.log('发送内容:', message);
|
||||
if (!err) {
|
||||
if (topic.indexOf('offline') > 0) {
|
||||
console.log("[ " + name + " ] 影子指令发送成功");
|
||||
resolve("[ " + name + " ] 影子指令发送成功");
|
||||
console.log('[ ' + name + ' ] 影子指令发送成功');
|
||||
resolve('[ ' + name + ' ] 影子指令发送成功');
|
||||
} else {
|
||||
console.log("[ " + name + " ] 指令发送成功");
|
||||
resolve("[ " + name + " ] 指令发送成功");
|
||||
console.log('[ ' + name + ' ] 指令发送成功');
|
||||
resolve('[ ' + name + ' ] 指令发送成功');
|
||||
}
|
||||
} else {
|
||||
console.log("[ " + name + " ] 指令发送失败");
|
||||
reject("[ " + name + " ] 指令发送失败");
|
||||
console.log('[ ' + name + ' ] 指令发送失败');
|
||||
reject('[ ' + name + ' ] 指令发送失败');
|
||||
return;
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default mqttTool
|
||||
export default mqttTool;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import axios from 'axios'
|
||||
import {Loading, Message, MessageBox, Notification} from 'element-ui'
|
||||
import { Notification, MessageBox, Message, Loading } from 'element-ui'
|
||||
import store from '@/store'
|
||||
import {getToken} from '@/utils/auth'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import errorCode from '@/utils/errorCode'
|
||||
import {blobValidate, tansParams} from "@/utils/ruoyi";
|
||||
import {saveAs} from 'file-saver'
|
||||
import { tansParams, blobValidate } from "@/utils/ruoyi";
|
||||
import cache from '@/plugins/cache'
|
||||
import { saveAs } from 'file-saver'
|
||||
|
||||
let downloadLoadingInstance;
|
||||
// 是否显示重新登录
|
||||
export let isRelogin = { show: false };
|
||||
|
||||
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
||||
// 创建axios实例
|
||||
@@ -14,13 +17,15 @@ const service = axios.create({
|
||||
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||||
baseURL: process.env.VUE_APP_BASE_API,
|
||||
// 超时
|
||||
timeout: 10000
|
||||
timeout: 20000
|
||||
})
|
||||
|
||||
// request拦截器
|
||||
service.interceptors.request.use(config => {
|
||||
// 是否需要设置 token
|
||||
const isToken = (config.headers || {}).isToken === false
|
||||
// 是否需要防止数据重复提交
|
||||
const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
|
||||
if (getToken() && !isToken) {
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||
}
|
||||
@@ -31,6 +36,29 @@ service.interceptors.request.use(config => {
|
||||
config.params = {};
|
||||
config.url = url;
|
||||
}
|
||||
if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
|
||||
const requestObj = {
|
||||
url: config.url,
|
||||
data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
|
||||
time: new Date().getTime()
|
||||
}
|
||||
const sessionObj = cache.session.getJSON('sessionObj')
|
||||
if (sessionObj === undefined || sessionObj === null || sessionObj === '') {
|
||||
cache.session.setJSON('sessionObj', requestObj)
|
||||
} else {
|
||||
const s_url = sessionObj.url; // 请求地址
|
||||
const s_data = sessionObj.data; // 请求数据
|
||||
const s_time = sessionObj.time; // 请求时间
|
||||
const interval = 1000; // 间隔时间(ms),小于此时间视为重复提交
|
||||
if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) {
|
||||
const message = '数据正在处理,请勿重复提交';
|
||||
console.warn(`[${s_url}]: ` + message)
|
||||
return Promise.reject(new Error(message))
|
||||
} else {
|
||||
cache.session.setJSON('sessionObj', requestObj)
|
||||
}
|
||||
}
|
||||
}
|
||||
return config
|
||||
}, error => {
|
||||
console.log(error)
|
||||
@@ -48,29 +76,26 @@ service.interceptors.response.use(res => {
|
||||
return res.data
|
||||
}
|
||||
if (code === 401) {
|
||||
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
||||
confirmButtonText: '重新登录',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
).then(() => {
|
||||
store.dispatch('LogOut').then(() => {
|
||||
location.href = '/index';
|
||||
})
|
||||
}).catch(() => {});
|
||||
if (!isRelogin.show) {
|
||||
isRelogin.show = true;
|
||||
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => {
|
||||
isRelogin.show = false;
|
||||
store.dispatch('LogOut').then(() => {
|
||||
location.href = '/index';
|
||||
})
|
||||
}).catch(() => {
|
||||
isRelogin.show = false;
|
||||
});
|
||||
}
|
||||
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
||||
} else if (code === 500) {
|
||||
Message({
|
||||
message: msg,
|
||||
type: 'error'
|
||||
})
|
||||
Message({ message: msg, type: 'error' })
|
||||
return Promise.reject(new Error(msg))
|
||||
} else if (code === 502) {
|
||||
} else if (code === 601) {
|
||||
Message({ message: msg, type: 'warning' })
|
||||
return Promise.reject('error')
|
||||
} else if (code !== 200) {
|
||||
Notification.error({
|
||||
title: msg
|
||||
})
|
||||
Notification.error({ title: msg })
|
||||
return Promise.reject('error')
|
||||
} else {
|
||||
return res.data
|
||||
@@ -81,36 +106,34 @@ service.interceptors.response.use(res => {
|
||||
let { message } = error;
|
||||
if (message == "Network Error") {
|
||||
message = "后端接口连接异常";
|
||||
}
|
||||
else if (message.includes("timeout")) {
|
||||
} else if (message.includes("timeout")) {
|
||||
message = "系统接口请求超时";
|
||||
}
|
||||
else if (message.includes("Request failed with status code")) {
|
||||
} else if (message.includes("Request failed with status code")) {
|
||||
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
||||
}
|
||||
Message({
|
||||
message: message,
|
||||
type: 'error',
|
||||
duration: 5 * 1000
|
||||
})
|
||||
Message({ message: message, type: 'error', duration: 5 * 1000 })
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// 通用下载方法
|
||||
export function download(url, params, filename) {
|
||||
export function download(url, params, filename, config) {
|
||||
downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", })
|
||||
return service.post(url, params, {
|
||||
transformRequest: [(params) => { return tansParams(params) }],
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
responseType: 'blob'
|
||||
responseType: 'blob',
|
||||
...config
|
||||
}).then(async (data) => {
|
||||
const isLogin = await blobValidate(data);
|
||||
if (isLogin) {
|
||||
const blob = new Blob([data])
|
||||
saveAs(blob, filename)
|
||||
} else {
|
||||
Message.error('无效的会话,或者会话已过期,请重新登录。');
|
||||
const resText = await data.text();
|
||||
const rspObj = JSON.parse(resText);
|
||||
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
||||
Message.error(errMsg);
|
||||
}
|
||||
downloadLoadingInstance.close();
|
||||
}).catch((r) => {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
/**
|
||||
* 通用js方法封装处理
|
||||
* Copyright (c) 2019 ruoyi
|
||||
@@ -5,130 +7,147 @@
|
||||
|
||||
// 日期格式化
|
||||
export 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(/{(y|m|d|h|i|s|a)+}/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
|
||||
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(/{(y|m|d|h|i|s|a)+}/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
|
||||
}
|
||||
|
||||
// 表单重置
|
||||
export function resetForm(refName) {
|
||||
if (this.$refs[refName]) {
|
||||
this.$refs[refName].resetFields();
|
||||
}
|
||||
if (this.$refs[refName]) {
|
||||
this.$refs[refName].resetFields();
|
||||
}
|
||||
}
|
||||
|
||||
// 添加日期范围
|
||||
export function addDateRange(params, dateRange, propName) {
|
||||
let search = params;
|
||||
search.params = typeof (search.params) === 'object' && search.params !== null && !Array.isArray(search.params) ? search.params : {};
|
||||
dateRange = Array.isArray(dateRange) ? dateRange : [];
|
||||
if (typeof (propName) === 'undefined') {
|
||||
search.params['beginTime'] = dateRange[0];
|
||||
search.params['endTime'] = dateRange[1];
|
||||
} else {
|
||||
search.params['begin' + propName] = dateRange[0];
|
||||
search.params['end' + propName] = dateRange[1];
|
||||
}
|
||||
return search;
|
||||
let search = params;
|
||||
search.params = typeof (search.params) === 'object' && search.params !== null && !Array.isArray(search.params) ? search.params : {};
|
||||
dateRange = Array.isArray(dateRange) ? dateRange : [];
|
||||
if (typeof (propName) === 'undefined') {
|
||||
search.params['beginTime'] = dateRange[0];
|
||||
search.params['endTime'] = dateRange[1];
|
||||
} else {
|
||||
search.params['begin' + propName] = dateRange[0];
|
||||
search.params['end' + propName] = dateRange[1];
|
||||
}
|
||||
return search;
|
||||
}
|
||||
|
||||
// 回显数据字典
|
||||
export function selectDictLabel(datas, value) {
|
||||
var actions = [];
|
||||
Object.keys(datas).some((key) => {
|
||||
if (datas[key].value == ('' + value)) {
|
||||
actions.push(datas[key].label);
|
||||
return true;
|
||||
}
|
||||
})
|
||||
return actions.join('');
|
||||
if (value === undefined) {
|
||||
return "";
|
||||
}
|
||||
var actions = [];
|
||||
Object.keys(datas).some((key) => {
|
||||
if (datas[key].value == ('' + value)) {
|
||||
actions.push(datas[key].label);
|
||||
return true;
|
||||
}
|
||||
})
|
||||
if (actions.length === 0) {
|
||||
actions.push(value);
|
||||
}
|
||||
return actions.join('');
|
||||
}
|
||||
|
||||
// 回显数据字典(字符串数组)
|
||||
// 回显数据字典(字符串、数组)
|
||||
export function selectDictLabels(datas, value, separator) {
|
||||
var actions = [];
|
||||
var currentSeparator = undefined === separator ? "," : separator;
|
||||
var temp = value.split(currentSeparator);
|
||||
Object.keys(value.split(currentSeparator)).some((val) => {
|
||||
Object.keys(datas).some((key) => {
|
||||
if (datas[key].value == ('' + temp[val])) {
|
||||
actions.push(datas[key].label + currentSeparator);
|
||||
}
|
||||
})
|
||||
})
|
||||
return actions.join('').substring(0, actions.join('').length - 1);
|
||||
if (value === undefined || value.length ===0) {
|
||||
return "";
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
value = value.join(",");
|
||||
}
|
||||
var actions = [];
|
||||
var currentSeparator = undefined === separator ? "," : separator;
|
||||
var temp = value.split(currentSeparator);
|
||||
Object.keys(value.split(currentSeparator)).some((val) => {
|
||||
var match = false;
|
||||
Object.keys(datas).some((key) => {
|
||||
if (datas[key].value == ('' + temp[val])) {
|
||||
actions.push(datas[key].label + currentSeparator);
|
||||
match = true;
|
||||
}
|
||||
})
|
||||
if (!match) {
|
||||
actions.push(temp[val] + currentSeparator);
|
||||
}
|
||||
})
|
||||
return actions.join('').substring(0, actions.join('').length - 1);
|
||||
}
|
||||
|
||||
// 字符串格式化(%s )
|
||||
export function sprintf(str) {
|
||||
var args = arguments, flag = true, i = 1;
|
||||
str = str.replace(/%s/g, function () {
|
||||
var arg = args[i++];
|
||||
if (typeof arg === 'undefined') {
|
||||
flag = false;
|
||||
return '';
|
||||
}
|
||||
return arg;
|
||||
});
|
||||
return flag ? str : '';
|
||||
var args = arguments, flag = true, i = 1;
|
||||
str = str.replace(/%s/g, function () {
|
||||
var arg = args[i++];
|
||||
if (typeof arg === 'undefined') {
|
||||
flag = false;
|
||||
return '';
|
||||
}
|
||||
return arg;
|
||||
});
|
||||
return flag ? str : '';
|
||||
}
|
||||
|
||||
// 转换字符串,undefined,null等转化为""
|
||||
export function praseStrEmpty(str) {
|
||||
if (!str || str == "undefined" || str == "null") {
|
||||
return "";
|
||||
}
|
||||
return str;
|
||||
export function parseStrEmpty(str) {
|
||||
if (!str || str == "undefined" || str == "null") {
|
||||
return "";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
// 数据合并
|
||||
export function mergeRecursive(source, target) {
|
||||
for (var p in target) {
|
||||
try {
|
||||
if (target[p].constructor == Object) {
|
||||
source[p] = mergeRecursive(source[p], target[p]);
|
||||
} else {
|
||||
source[p] = target[p];
|
||||
}
|
||||
} catch(e) {
|
||||
source[p] = target[p];
|
||||
}
|
||||
for (var p in target) {
|
||||
try {
|
||||
if (target[p].constructor == Object) {
|
||||
source[p] = mergeRecursive(source[p], target[p]);
|
||||
} else {
|
||||
source[p] = target[p];
|
||||
}
|
||||
} catch (e) {
|
||||
source[p] = target[p];
|
||||
}
|
||||
return source;
|
||||
}
|
||||
return source;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -139,47 +158,47 @@ export function mergeRecursive(source, target) {
|
||||
* @param {*} children 孩子节点字段 默认 'children'
|
||||
*/
|
||||
export function handleTree(data, id, parentId, children) {
|
||||
let config = {
|
||||
id: id || 'id',
|
||||
parentId: parentId || 'parentId',
|
||||
childrenList: children || 'children'
|
||||
};
|
||||
let config = {
|
||||
id: id || 'id',
|
||||
parentId: parentId || 'parentId',
|
||||
childrenList: children || 'children'
|
||||
};
|
||||
|
||||
var childrenListMap = {};
|
||||
var nodeIds = {};
|
||||
var tree = [];
|
||||
var childrenListMap = {};
|
||||
var nodeIds = {};
|
||||
var tree = [];
|
||||
|
||||
for (let d of data) {
|
||||
let parentId = d[config.parentId];
|
||||
if (childrenListMap[parentId] == null) {
|
||||
childrenListMap[parentId] = [];
|
||||
}
|
||||
nodeIds[d[config.id]] = d;
|
||||
childrenListMap[parentId].push(d);
|
||||
}
|
||||
for (let d of data) {
|
||||
let parentId = d[config.parentId];
|
||||
if (childrenListMap[parentId] == null) {
|
||||
childrenListMap[parentId] = [];
|
||||
}
|
||||
nodeIds[d[config.id]] = d;
|
||||
childrenListMap[parentId].push(d);
|
||||
}
|
||||
|
||||
for (let d of data) {
|
||||
let parentId = d[config.parentId];
|
||||
if (nodeIds[parentId] == null) {
|
||||
tree.push(d);
|
||||
}
|
||||
}
|
||||
for (let d of data) {
|
||||
let parentId = d[config.parentId];
|
||||
if (nodeIds[parentId] == null) {
|
||||
tree.push(d);
|
||||
}
|
||||
}
|
||||
|
||||
for (let t of tree) {
|
||||
adaptToChildrenList(t);
|
||||
}
|
||||
for (let t of tree) {
|
||||
adaptToChildrenList(t);
|
||||
}
|
||||
|
||||
function adaptToChildrenList(o) {
|
||||
if (childrenListMap[o[config.id]] !== null) {
|
||||
o[config.childrenList] = childrenListMap[o[config.id]];
|
||||
}
|
||||
if (o[config.childrenList]) {
|
||||
for (let c of o[config.childrenList]) {
|
||||
adaptToChildrenList(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
function adaptToChildrenList(o) {
|
||||
if (childrenListMap[o[config.id]] !== null) {
|
||||
o[config.childrenList] = childrenListMap[o[config.id]];
|
||||
}
|
||||
if (o[config.childrenList]) {
|
||||
for (let c of o[config.childrenList]) {
|
||||
adaptToChildrenList(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,34 +206,34 @@ export function handleTree(data, id, parentId, children) {
|
||||
* @param {*} params 参数
|
||||
*/
|
||||
export function tansParams(params) {
|
||||
let result = ''
|
||||
for (const propName of Object.keys(params)) {
|
||||
const value = params[propName];
|
||||
var part = encodeURIComponent(propName) + "=";
|
||||
if (value !== null && typeof (value) !== "undefined") {
|
||||
if (typeof value === 'object') {
|
||||
for (const key of Object.keys(value)) {
|
||||
if (value[key] !== null && typeof (value[key]) !== 'undefined') {
|
||||
let params = propName + '[' + key + ']';
|
||||
var subPart = encodeURIComponent(params) + "=";
|
||||
result += subPart + encodeURIComponent(value[key]) + "&";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result += part + encodeURIComponent(value) + "&";
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
let result = ''
|
||||
for (const propName of Object.keys(params)) {
|
||||
const value = params[propName];
|
||||
var part = encodeURIComponent(propName) + "=";
|
||||
if (value !== null && value !== "" && typeof (value) !== "undefined") {
|
||||
if (typeof value === 'object') {
|
||||
for (const key of Object.keys(value)) {
|
||||
if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
|
||||
let params = propName + '[' + key + ']';
|
||||
var subPart = encodeURIComponent(params) + "=";
|
||||
result += subPart + encodeURIComponent(value[key]) + "&";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result += part + encodeURIComponent(value) + "&";
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 验证是否为blob格式
|
||||
export async function blobValidate(data) {
|
||||
try {
|
||||
const text = await data.text();
|
||||
JSON.parse(text);
|
||||
return false;
|
||||
} catch (error) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
const text = await data.text();
|
||||
JSON.parse(text);
|
||||
return false;
|
||||
} catch (error) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,3 +81,34 @@ export function isArray(arg) {
|
||||
}
|
||||
return Array.isArray(arg)
|
||||
}
|
||||
//<2F><>ֵ<EFBFBD><D6B5>ΧУ<CEA7><D0A3>
|
||||
export function checkNumber(rule, value, callback) {
|
||||
if (!value) {
|
||||
return callback(new Error('<27><><EFBFBD>벻<EFBFBD><EBB2BB><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>'));
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (!Number(value)) {
|
||||
} else {
|
||||
if (value < 1 || value > 64) {
|
||||
callback(new Error('<27><>ֵ<EFBFBD><D6B5>ΧΪ1-64'));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
export function checkNumberAddr(rule, value, callback) {
|
||||
if (!value) {
|
||||
return callback(new Error('<27><><EFBFBD>벻<EFBFBD><EBB2BB><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>'));
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (!Number(value)) {
|
||||
} else {
|
||||
if (value < 1 || value > 65536) {
|
||||
callback(new Error('<27><>ֵ<EFBFBD><D6B5>ΧΪ1-65536'));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user