xs-common-plugins 1.1.7 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/package.json +1 -1
- package/src/common/common.js +37 -10
- package/src/utils/filterRules.js +10 -5
- package/src/views/layout/components/Navbar.vue +2 -2
package/README.md
CHANGED
package/package.json
CHANGED
package/src/common/common.js
CHANGED
|
@@ -5,7 +5,7 @@ import store from '@/store/index'
|
|
|
5
5
|
import {OrgEnum} from '@/utils/enum'
|
|
6
6
|
import filterRules from '@/utils/filterRules'
|
|
7
7
|
import request from "xs-request";
|
|
8
|
-
|
|
8
|
+
import moduleCfg from '@/modules/module.config.js'
|
|
9
9
|
const common = {}
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -400,28 +400,45 @@ common.requiredList = (list) => {
|
|
|
400
400
|
/**
|
|
401
401
|
* 格式化数据样式
|
|
402
402
|
* @param {*} value 值
|
|
403
|
-
* @param {*} type 要格式化的类型 [date, price]
|
|
403
|
+
* @param {*} type 要格式化的类型 [date, price, price, money, enum, list(前端自定义枚举)]
|
|
404
404
|
* @returns
|
|
405
405
|
*/
|
|
406
406
|
common.format = (value, type="date") => {
|
|
407
|
-
|
|
407
|
+
let newType = ['money', 'date', 'mdate'].includes(type) ? type : type.split('.').length > 1 ? 'enum' : 'list'
|
|
408
|
+
switch (newType) {
|
|
409
|
+
case 'money':
|
|
410
|
+
return Number(value).toFixed(4);
|
|
408
411
|
case 'date':
|
|
409
|
-
if(value) return
|
|
410
|
-
|
|
411
|
-
|
|
412
|
+
if(value === '1970-01-01T00:00:00') return '/'
|
|
413
|
+
return value ? value.replace('T', ' ').substr(0, 19) : ''
|
|
414
|
+
case 'mdate':
|
|
415
|
+
if(value === '1970-01-01T00:00:00') return '/'
|
|
416
|
+
return value ? value.replace('T', ' ').substr(5, 19) : ''
|
|
412
417
|
case 'price':
|
|
413
418
|
if(typeof(value) === 'number') {
|
|
414
419
|
return value.toFixed(2).toString().replace(/,/g,'').replace(/\d+/, function (n) { // 先提取整数部分
|
|
415
420
|
return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { // 对整数部分添加分隔符
|
|
416
|
-
|
|
421
|
+
return $1 + ",";
|
|
417
422
|
});
|
|
418
423
|
});
|
|
419
424
|
}
|
|
420
425
|
else return ''
|
|
421
|
-
|
|
426
|
+
case 'enum':
|
|
427
|
+
return getValueByType('enum', type, value)
|
|
428
|
+
case 'list':
|
|
429
|
+
return getValueByType('list', type, value)
|
|
422
430
|
default:
|
|
423
431
|
break;
|
|
424
432
|
}
|
|
433
|
+
function getValueByType (type, name, value) {
|
|
434
|
+
if(type === 'enum') {
|
|
435
|
+
let row = OrgEnum[name].find(item => item.Id == value)
|
|
436
|
+
return row ? row.Text : ''
|
|
437
|
+
} else if(type === 'list') {
|
|
438
|
+
let row = moduleCfg.format ? moduleCfg.format[name].find(item => item.id == value) : null
|
|
439
|
+
return row ? row.name: ''
|
|
440
|
+
}
|
|
441
|
+
}
|
|
425
442
|
}
|
|
426
443
|
|
|
427
444
|
/**
|
|
@@ -476,7 +493,7 @@ common.getReportList = (that, url, query, callBack) => {
|
|
|
476
493
|
|
|
477
494
|
|
|
478
495
|
/**
|
|
479
|
-
* 字典表 里通过Id 查 name, 或者查询多条数据
|
|
496
|
+
* 字典表 里通过Id 查 name, 或者查询多条数据 (单条返回 name, 多条返回数组)
|
|
480
497
|
* @param {Array} props ['服务名', '表名', '字段名']
|
|
481
498
|
* @param {String, Number, Array} val 值, 传入id, 或者 [id1, id2, ...]
|
|
482
499
|
*
|
|
@@ -518,5 +535,15 @@ common.dic = async (props, val) => {
|
|
|
518
535
|
}
|
|
519
536
|
}
|
|
520
537
|
}
|
|
521
|
-
|
|
538
|
+
/**
|
|
539
|
+
* 快速给页面变量赋值
|
|
540
|
+
* @param {*} url 请求接口的地址
|
|
541
|
+
* @param {*} query 接口参数
|
|
542
|
+
* @param {*} prop 要为哪个字段名赋值
|
|
543
|
+
*/
|
|
544
|
+
common.getLabelList = (that, prop, url, query) => {
|
|
545
|
+
common.getObject(url)(query).then(res => {
|
|
546
|
+
that[prop] = res.data
|
|
547
|
+
})
|
|
548
|
+
}
|
|
522
549
|
export default common
|
package/src/utils/filterRules.js
CHANGED
|
@@ -2,11 +2,16 @@ const filterRules = ({ required, type, min, max }) => {
|
|
|
2
2
|
let validate = [];
|
|
3
3
|
if (required) {
|
|
4
4
|
// 必填项
|
|
5
|
-
validate.push({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
validate.push({ required: true, message: "该输入项为必填项", trigger: "change",});
|
|
6
|
+
}
|
|
7
|
+
if(min&&max){
|
|
8
|
+
validate.push({ min:min,max:max, message: '字符长度在'+min+'至'+max+'之间!', trigger: 'change' })
|
|
9
|
+
}
|
|
10
|
+
if(min){
|
|
11
|
+
validate.push({ min:min, message: '最少输入'+min+'个字符!', trigger: 'change' })
|
|
12
|
+
}
|
|
13
|
+
if(max){
|
|
14
|
+
validate.push({ min:1,max:max, message: '最多输入'+max+'个字符!', trigger: 'change' })
|
|
10
15
|
}
|
|
11
16
|
if (type) {
|
|
12
17
|
let message = "";
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
</el-tag>
|
|
65
65
|
</div>
|
|
66
66
|
<!-- 租户 -->
|
|
67
|
-
<div class="tenant" v-if="userProfile.TId">
|
|
67
|
+
<div class="tenant" v-if="userProfile && userProfile.TId">
|
|
68
68
|
<el-dropdown @command="changeTenant">
|
|
69
69
|
<span class="el-dropdown-link">
|
|
70
70
|
{{tenantList && tenantList[userProfile.TId]}}
|
|
@@ -161,7 +161,7 @@ export default {
|
|
|
161
161
|
if (userName === "admin") {
|
|
162
162
|
this.LoginName = true;
|
|
163
163
|
}
|
|
164
|
-
if(this.userProfile.TId) this.getTenantList()
|
|
164
|
+
if(this.userProfile &&this.userProfile.TId) this.getTenantList()
|
|
165
165
|
},
|
|
166
166
|
methods: {
|
|
167
167
|
changeTenant (id) {
|