优化逻辑

dev
smallchill 6 years ago
parent ef020657eb
commit 02de800cce
  1. 45
      src/util/func.js
  2. 20
      src/views/authority/datascope.vue

@ -1,18 +1,23 @@
/** /**
* 通用工具类
*/
export default class func {
/**
* 不为空 * 不为空
* @param val * @param val
* @returns {boolean} * @returns {boolean}
*/ */
export function notEmpty(val) { static notEmpty(val) {
return !this.isEmpty(val); return !this.isEmpty(val);
} }
/** /**
* 为空 * 为空
* @param val * @param val
* @returns {boolean} * @returns {boolean}
*/ */
export function isEmpty(val) { static isEmpty(val) {
if ( if (
val === null || val === null ||
typeof val === 'undefined' || typeof val === 'undefined' ||
@ -21,60 +26,60 @@ export function isEmpty(val) {
return true; return true;
} }
return false; return false;
} }
/** /**
* 强转int型 * 强转int型
* @param val * @param val
* @param defaultValue * @param defaultValue
* @returns {number} * @returns {number}
*/ */
export function toInt(val, defaultValue) { static toInt(val, defaultValue) {
if (this.isEmpty(val)) { if (this.isEmpty(val)) {
return defaultValue === undefined ? -1 : defaultValue; return defaultValue === undefined ? -1 : defaultValue;
} }
const num = parseInt(val, 0); const num = parseInt(val, 0);
return Number.isNaN(num) ? (defaultValue === undefined ? -1 : defaultValue) : num; return Number.isNaN(num) ? (defaultValue === undefined ? -1 : defaultValue) : num;
} }
/** /**
* Json强转为Form类型 * Json强转为Form类型
* @param obj * @param obj
* @returns {FormData} * @returns {FormData}
*/ */
export function toFormData(obj) { static toFormData(obj) {
const data = new FormData(); const data = new FormData();
Object.keys(obj).forEach(key => { Object.keys(obj).forEach(key => {
data.append(key, Array.isArray(obj[key]) ? obj[key].join(',') : obj[key]); data.append(key, Array.isArray(obj[key]) ? obj[key].join(',') : obj[key]);
}); });
return data; return data;
} }
/** /**
* date类转为字符串格式 * date类转为字符串格式
* @param date * @param date
* @param format * @param format
* @returns {null} * @returns {null}
*/ */
export function format(date, format = 'YYYY-MM-DD HH:mm:ss') { static format(date, format = 'YYYY-MM-DD HH:mm:ss') {
return date ? date.format(format) : null; return date ? date.format(format) : null;
} }
/** /**
* 根据逗号联合 * 根据逗号联合
* @param arr * @param arr
* @returns {string} * @returns {string}
*/ */
export function join(arr) { static join(arr) {
return arr ? arr.join(',') : ''; return arr ? arr.join(',') : '';
} }
/** /**
* 根据逗号分隔 * 根据逗号分隔
* @param str * @param str
* @returns {string} * @returns {string}
*/ */
export function split(str) { static split(str) {
return str ? String(str).split(',') : ''; return str ? String(str).split(',') : '';
}
} }

@ -87,6 +87,7 @@
} from "@/api/system/scope"; } from "@/api/system/scope";
import {mapGetters} from "vuex"; import {mapGetters} from "vuex";
import iconList from "@/config/iconList"; import iconList from "@/config/iconList";
import func from "@/util/func";
export default { export default {
data() { data() {
@ -431,26 +432,27 @@
}, },
methods: { methods: {
initScope() { initScope() {
if (this.watchMode) { const scopeType = func.toInt(this.formScope.scopeType);
const scopeType = this.formScope.scopeType; const watchMode = this.watchMode;
let column = "-", name = "暂无"; let column = "-", name = "暂无";
if (scopeType === "1") { if (scopeType === 1) {
column = "-"; column = "-";
name = "全部可见"; name = "全部可见";
} else if (scopeType === "2") { } else if (scopeType === 2) {
column = "create_user"; column = "create_user";
name = "本人可见"; name = "本人可见";
} else if (scopeType === "3") { } else if (scopeType === 3) {
column = "create_dept"; column = "create_dept";
name = "所在机构可见"; name = "所在机构可见";
} else if (scopeType === "4") { } else if (scopeType === 4) {
column = "create_dept"; column = "create_dept";
name = "所在机构可见及子级可见"; name = "所在机构可见及子级可见";
} else if (scopeType === "5") { } else if (scopeType === 5) {
column = ""; column = "";
name = "自定义"; name = "自定义";
} }
this.$refs.crudScope.option.column.filter(item => { this.$refs.crudScope.option.column.filter(item => {
if (watchMode) {
if (item.prop === "scopeName") { if (item.prop === "scopeName") {
this.formScope.scopeName = `${this.scopeMenuName} [${name}]`; this.formScope.scopeName = `${this.scopeMenuName} [${name}]`;
} }
@ -460,11 +462,11 @@
if (item.prop === "scopeColumn") { if (item.prop === "scopeColumn") {
this.formScope.scopeColumn = column; this.formScope.scopeColumn = column;
} }
}
if (item.prop === "scopeValue") { if (item.prop === "scopeValue") {
item.display = scopeType === '5'; item.display = scopeType === 5;
} }
}); });
}
}, },
// //
rowSave(row, loading, done) { rowSave(row, loading, done) {

Loading…
Cancel
Save