xs-common-plugins 1.1.4 → 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 CHANGED
@@ -264,4 +264,24 @@
264
264
  1. common.js 增加 common.updateData() 修改数据后, 刷新列表页函数
265
265
  2. dic 字段, 移除 '0' 字符串 0 的 参数
266
266
  3. 移除 common.getReportList() 获取列表页数据 函数 空数据入参
267
+ ```
268
+ ```
269
+ 1.1.5
270
+ 1. common.js common.exportExcel (报表导出) 方法, 移除空条件
271
+ ```
272
+ ```
273
+ 1.1.6
274
+ 1. 增加多租户却换
275
+ 2. 兼容相同路由跳转警告问题
276
+ 3. common.js 增加公用方法 this.$common.dic() 用于查询字典单条/多条数据
277
+ ```
278
+ ```
279
+ 1.1.7
280
+ 1. 多余显示移除
281
+ ```
282
+ ```
283
+ 1.1.8
284
+ 1. common.js 增加 方法
285
+ 2. common.js commom.format() 拓展类型枚举
286
+ 3. 表单校验增加 min, max 参数
267
287
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xs-common-plugins",
3
- "version": "1.1.4",
3
+ "version": "1.1.8",
4
4
  "private": false,
5
5
  "description": "向上公共代码部分",
6
6
  "author": "祝玲云 <1902733517@qq.com>",
@@ -4,7 +4,8 @@ import router from '@/router/index'
4
4
  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
+ import moduleCfg from '@/modules/module.config.js'
8
9
  const common = {}
9
10
 
10
11
  /**
@@ -350,6 +351,10 @@ common.clone = (obj) => {
350
351
  common.exportExcel = async (url, query, fileName = 'demo', headers = { responseType: 'arraybuffer' }) => {
351
352
  let newQuery = JSON.parse(JSON.stringify(query))
352
353
  delete newQuery.data
354
+ for (const key in newQuery) {
355
+ if(newQuery[key] == null || newQuery[key] === '')
356
+ delete newQuery[key]
357
+ }
353
358
  const httpRequest = common.getObject(url)
354
359
  const response = await httpRequest(newQuery, headers)
355
360
  const blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' })
@@ -395,28 +400,45 @@ common.requiredList = (list) => {
395
400
  /**
396
401
  * 格式化数据样式
397
402
  * @param {*} value 值
398
- * @param {*} type 要格式化的类型 [date, price]
403
+ * @param {*} type 要格式化的类型 [date, price, price, money, enum, list(前端自定义枚举)]
399
404
  * @returns
400
405
  */
401
406
  common.format = (value, type="date") => {
402
- switch (type) {
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);
403
411
  case 'date':
404
- if(value) return value.replace("T", ' ').substr(0, 19)
405
- else return ''
406
- break;
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) : ''
407
417
  case 'price':
408
418
  if(typeof(value) === 'number') {
409
419
  return value.toFixed(2).toString().replace(/,/g,'').replace(/\d+/, function (n) { // 先提取整数部分
410
420
  return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { // 对整数部分添加分隔符
411
- return $1 + ",";
421
+ return $1 + ",";
412
422
  });
413
423
  });
414
424
  }
415
425
  else return ''
416
- break;
426
+ case 'enum':
427
+ return getValueByType('enum', type, value)
428
+ case 'list':
429
+ return getValueByType('list', type, value)
417
430
  default:
418
431
  break;
419
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
+ }
420
442
  }
421
443
 
422
444
  /**
@@ -469,4 +491,59 @@ common.getReportList = (that, url, query, callBack) => {
469
491
  })
470
492
  }
471
493
 
494
+
495
+ /**
496
+ * 字典表 里通过Id 查 name, 或者查询多条数据 (单条返回 name, 多条返回数组)
497
+ * @param {Array} props ['服务名', '表名', '字段名']
498
+ * @param {String, Number, Array} val 值, 传入id, 或者 [id1, id2, ...]
499
+ *
500
+ * 使用案例 (异步方法)
501
+ * async getValue () {
502
+ * await this.$common.dic(['qccuser', 'Brand'], '10010')
503
+ * }
504
+ *
505
+ */
506
+
507
+ common.dic = async (props, val) => {
508
+ let isArray = Array.isArray(val)
509
+ let server = props[0] || ''
510
+ let tableName = props[1] || ''
511
+ let prop = props[2] || 'name'
512
+ let key = server + tableName
513
+ if(store.getters.dic[key]) {
514
+ if(isArray) return await getDicVal()
515
+ let row = store.getters.dic[key].find(item => item.id == val)
516
+ if(row && (row.isNull || row[prop] === null)) { return '' }
517
+ if(row) return row[prop]
518
+ if(!row) return await getDicVal()
519
+
520
+ } else {
521
+ return await getDicVal()
522
+ }
523
+ async function getDicVal () {
524
+ let servers = props[0] || "";
525
+ let tableName = props[1] || "";
526
+ let key = servers + tableName;
527
+ let url = servers + "/UserAll/Search/Dic/" + tableName;
528
+ let res = await request.post(url, isArray ? val : [val])
529
+ if (res.code !== 0) return;
530
+ store.commit("dic/SET_ASK", { key, val: res.data });
531
+ if(isArray) return res.data
532
+ else {
533
+ let row = res.data.find(item => item.id == val)
534
+ return row ? row[prop] : ''
535
+ }
536
+ }
537
+ }
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
+ }
472
549
  export default common
@@ -3,6 +3,10 @@ import VueRouter from 'vue-router'
3
3
  import autoRouter from '../automatically/router'
4
4
  Vue.use(VueRouter)
5
5
 
6
+ const originalPush = VueRouter.prototype.push;
7
+ VueRouter.prototype.push = function push(location) {
8
+ return originalPush.call(this, location).catch(err => err)
9
+ }
6
10
  const routes = [
7
11
  {
8
12
  path: '/',
@@ -2,11 +2,16 @@ const filterRules = ({ required, type, min, max }) => {
2
2
  let validate = [];
3
3
  if (required) {
4
4
  // 必填项
5
- validate.push({
6
- required: true,
7
- message: "该输入项为必填项",
8
- trigger: "change",
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 = "";
@@ -77,6 +77,7 @@ function getApis () {
77
77
 
78
78
  export {
79
79
 
80
- main
80
+ main,
81
+ initMenu
81
82
 
82
83
  }
@@ -31,6 +31,7 @@
31
31
  <AllSearch />
32
32
  <div class="is-dot">
33
33
  <el-badge
34
+ style="margin: 0 3px;"
34
35
  v-if="isShowKF === 'isv' || isShowKF === 'erp'"
35
36
  is-dot
36
37
  class="item"
@@ -45,7 +46,7 @@
45
46
  </el-badge>
46
47
  </div>
47
48
  <div>
48
- <el-tag>{{
49
+ <el-tag style="margin: 0 3px;">{{
49
50
  userProfile &&
50
51
  userProfile.hasOwnProperty("real_name") &&
51
52
  userProfile.real_name
@@ -61,6 +62,17 @@
61
62
  : "--未绑定--"
62
63
  }}
63
64
  </el-tag>
65
+ </div>
66
+ <!-- 租户 -->
67
+ <div class="tenant" v-if="userProfile && userProfile.TId">
68
+ <el-dropdown @command="changeTenant">
69
+ <span class="el-dropdown-link">
70
+ {{tenantList && tenantList[userProfile.TId]}}
71
+ </span>
72
+ <el-dropdown-menu slot="dropdown">
73
+ <el-dropdown-item v-for="(value, key) in tenantList" :key="key" :command="key">{{value}}</el-dropdown-item>
74
+ </el-dropdown-menu>
75
+ </el-dropdown>
64
76
  </div>
65
77
  <el-dropdown class="avatar-container" trigger="click">
66
78
  <div class="avatar-wrapper">
@@ -107,7 +119,9 @@ import AllSearch from "./AllSearch";
107
119
  import { getConfig } from "@/utils/global-config";
108
120
  import { getToken, removeToken, removeLocalToken } from "@/utils/auth"; // get token from cookie
109
121
  import ImCom from "@/components/im";
110
- import { getLocalStorage } from "@/utils/localStorage";
122
+ import { getLocalStorage, setLocalStorage } from "@/utils/localStorage";
123
+ import { setToken } from "@/utils/auth"; // get token from cookie
124
+ import { initMenu } from '@/utils/getMenu'
111
125
 
112
126
  export default {
113
127
  components: {
@@ -136,6 +150,7 @@ export default {
136
150
  LoginName: false,
137
151
  isShowKF: getConfig("GROUP"),
138
152
  defaultParentId: "887904812217cca9bc2b9adb875daf42",
153
+ tenantList: [], // 租户列表
139
154
  };
140
155
  },
141
156
  computed: {
@@ -146,8 +161,29 @@ export default {
146
161
  if (userName === "admin") {
147
162
  this.LoginName = true;
148
163
  }
164
+ if(this.userProfile &&this.userProfile.TId) this.getTenantList()
149
165
  },
150
166
  methods: {
167
+ changeTenant (id) {
168
+ if(id === this.userProfile.TId) return
169
+ this.$router.push("/home")
170
+ this.$ask.ucmng.api.sysmng.Tenant.SwitchTenant({clientId: getConfig('CLIENT_ID'), newTId: id}).then(res => {
171
+ let newuser = this.userProfile
172
+ newuser.TId = id
173
+ setLocalStorage('userProfile', newuser)
174
+ this.userProfile = getLocalStorage('userProfile')
175
+ let user = res.data
176
+ setToken(user.accessToken);
177
+ localStorage.setItem("token", user.accessToken);
178
+ initMenu()
179
+
180
+ })
181
+ },
182
+ getTenantList () {
183
+ this.$ask.ucmng.api.sysmng.Tenant.GetTenants().then(res => {
184
+ this.tenantList = res.data
185
+ })
186
+ },
151
187
  toggleSideBar() {
152
188
  this.$store.dispatch("app/toggleSideBar");
153
189
  },
@@ -279,6 +315,10 @@ export default {
279
315
  }
280
316
  }
281
317
 
318
+ .tenant {
319
+ padding: 0 10px;
320
+ }
321
+
282
322
  .breadcrumb-container {
283
323
  float: left;
284
324
  }