优化逻辑

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

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

Loading…
Cancel
Save