From 02de800cce2e6e593b01ad49de1fa13fa1736f44 Mon Sep 17 00:00:00 2001 From: smallchill Date: Thu, 5 Dec 2019 14:17:53 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/func.js | 143 ++++++++++++++++-------------- src/views/authority/datascope.vue | 52 +++++------ 2 files changed, 101 insertions(+), 94 deletions(-) diff --git a/src/util/func.js b/src/util/func.js index bb15ac1..2a86d88 100644 --- a/src/util/func.js +++ b/src/util/func.js @@ -1,80 +1,85 @@ -/** - * 不为空 - * @param val - * @returns {boolean} - */ -export function notEmpty(val) { - return !this.isEmpty(val); -} /** - * 为空 - * @param val - * @returns {boolean} + * 通用工具类 */ -export function isEmpty(val) { - if ( - val === null || - typeof val === 'undefined' || - (typeof val === 'string' && val === '' && val !== 'undefined') - ) { - return true; +export default class func { + /** + * 不为空 + * @param val + * @returns {boolean} + */ + static notEmpty(val) { + return !this.isEmpty(val); } - return false; -} -/** - * 强转int型 - * @param val - * @param defaultValue - * @returns {number} - */ -export function toInt(val, defaultValue) { - if (this.isEmpty(val)) { - return defaultValue === undefined ? -1 : defaultValue; + /** + * 为空 + * @param val + * @returns {boolean} + */ + static isEmpty(val) { + if ( + val === null || + typeof val === 'undefined' || + (typeof val === 'string' && val === '' && val !== 'undefined') + ) { + return true; + } + return false; } - const num = parseInt(val, 0); - return Number.isNaN(num) ? (defaultValue === undefined ? -1 : defaultValue) : num; -} -/** - * Json强转为Form类型 - * @param obj - * @returns {FormData} - */ -export function toFormData(obj) { - const data = new FormData(); - Object.keys(obj).forEach(key => { - data.append(key, Array.isArray(obj[key]) ? obj[key].join(',') : obj[key]); - }); - return data; -} + /** + * 强转int型 + * @param val + * @param defaultValue + * @returns {number} + */ + static toInt(val, defaultValue) { + if (this.isEmpty(val)) { + return defaultValue === undefined ? -1 : defaultValue; + } + const num = parseInt(val, 0); + return Number.isNaN(num) ? (defaultValue === undefined ? -1 : defaultValue) : num; + } -/** - * date类转为字符串格式 - * @param date - * @param format - * @returns {null} - */ -export function format(date, format = 'YYYY-MM-DD HH:mm:ss') { - return date ? date.format(format) : null; -} + /** + * Json强转为Form类型 + * @param obj + * @returns {FormData} + */ + static toFormData(obj) { + const data = new FormData(); + Object.keys(obj).forEach(key => { + data.append(key, Array.isArray(obj[key]) ? obj[key].join(',') : obj[key]); + }); + return data; + } -/** - * 根据逗号联合 - * @param arr - * @returns {string} - */ -export function join(arr) { - return arr ? arr.join(',') : ''; -} + /** + * date类转为字符串格式 + * @param date + * @param format + * @returns {null} + */ + static format(date, format = 'YYYY-MM-DD HH:mm:ss') { + return date ? date.format(format) : null; + } -/** - * 根据逗号分隔 - * @param str - * @returns {string} - */ -export function split(str) { - return str ? String(str).split(',') : ''; -} + /** + * 根据逗号联合 + * @param arr + * @returns {string} + */ + static join(arr) { + return arr ? arr.join(',') : ''; + } + /** + * 根据逗号分隔 + * @param str + * @returns {string} + */ + static split(str) { + return str ? String(str).split(',') : ''; + } +} diff --git a/src/views/authority/datascope.vue b/src/views/authority/datascope.vue index 0b85410..f04a0c3 100644 --- a/src/views/authority/datascope.vue +++ b/src/views/authority/datascope.vue @@ -87,6 +87,7 @@ } from "@/api/system/scope"; import {mapGetters} from "vuex"; import iconList from "@/config/iconList"; + import func from "@/util/func"; export default { data() { @@ -431,26 +432,27 @@ }, methods: { initScope() { - if (this.watchMode) { - const scopeType = this.formScope.scopeType; - let column = "-", name = "暂无"; - if (scopeType === "1") { - column = "-"; - name = "全部可见"; - } else if (scopeType === "2") { - column = "create_user"; - name = "本人可见"; - } else if (scopeType === "3") { - column = "create_dept"; - name = "所在机构可见"; - } else if (scopeType === "4") { - column = "create_dept"; - name = "所在机构可见及子级可见"; - } else if (scopeType === "5") { - column = ""; - name = "自定义"; - } - this.$refs.crudScope.option.column.filter(item => { + const scopeType = func.toInt(this.formScope.scopeType); + const watchMode = this.watchMode; + let column = "-", name = "暂无"; + if (scopeType === 1) { + column = "-"; + name = "全部可见"; + } else if (scopeType === 2) { + column = "create_user"; + name = "本人可见"; + } else if (scopeType === 3) { + column = "create_dept"; + name = "所在机构可见"; + } else if (scopeType === 4) { + column = "create_dept"; + name = "所在机构可见及子级可见"; + } else if (scopeType === 5) { + column = ""; + name = "自定义"; + } + this.$refs.crudScope.option.column.filter(item => { + if (watchMode) { if (item.prop === "scopeName") { this.formScope.scopeName = `${this.scopeMenuName} [${name}]`; } @@ -460,11 +462,11 @@ if (item.prop === "scopeColumn") { this.formScope.scopeColumn = column; } - if (item.prop === "scopeValue") { - item.display = scopeType === '5'; - } - }); - } + } + if (item.prop === "scopeValue") { + item.display = scopeType === 5; + } + }); }, // 菜单管理模块 rowSave(row, loading, done) {