diff --git a/examples/main.js b/examples/main.js
index 668ac71..9edf5f8 100644
--- a/examples/main.js
+++ b/examples/main.js
@@ -2,6 +2,7 @@ import Vue from 'vue';
import App from '@/App.vue';
import router from '@/router';
import store from '@/store';
+import request from '@/utils/request';
import ElementUI from 'element-ui';
import Zee from '../packages';
import NProgress from 'nprogress';
@@ -18,8 +19,12 @@ Vue.component('code-snippet', CodeSnippet);
// 注册饿了么UI
Vue.use(ElementUI);
// 注册Zee组件库
-Vue.use(Zee);
+Vue.use(Zee, {
+ alias: { list: 'result', total: 'totalCount' },
+ http: request,
+});
+Vue.prototype.$http = request;
Vue.config.productionTip = false;
new Vue({
diff --git a/examples/utils/cache.js b/examples/utils/cache.js
new file mode 100644
index 0000000..907aedf
--- /dev/null
+++ b/examples/utils/cache.js
@@ -0,0 +1,86 @@
+const __DEBUG__ = process.env.NODE_ENV !== 'production';
+/**
+ * 缓存数据优化
+ * import cache from '@/utils/cache'
+ * 使用方法 【
+ * 一、设置缓存
+ * string cache.put('k', 'string你好啊');
+ * json cache.put('k', { "b": "3" }, 2);
+ * array cache.put('k', [1, 2, 3]);
+ * boolean cache.put('k', true);
+ * 二、读取缓存
+ * 默认值 cache.get('k')
+ * string cache.get('k', '你好')
+ * json cache.get('k', { "a": "1" })
+ * 三、移除/清理
+ * 移除: cache.remove('k');
+ * 清理:cache.clear();
+ * 】
+ * @type {String}
+ */
+const prefix = __DEBUG__ ? 'ZY_AUTH_DEV_' : 'ZY_AUTH_'; // 缓存前缀
+const postfix = '_SEED';
+/**
+ * 设置缓存
+ * @param {[type]} k [键名]
+ * @param {[type]} v [键值]
+ * @param {[type]} t [时间、单位秒]
+ */
+function put(k, v, t) {
+ localStorage.setItem(prefix + k, JSON.stringify(v));
+ var seconds = parseInt(t);
+ if (seconds > 0) {
+ var timestamp = Date.parse(new Date());
+ timestamp = timestamp / 1000 + seconds;
+ localStorage.setItem(prefix + k + postfix, JSON.stringify(timestamp));
+ } else {
+ localStorage.removeItem(prefix + k + postfix);
+ }
+}
+
+/**
+ * 获取缓存
+ * @param {[type]} k [键名]
+ * @param {[type]} def [获取为空时默认]
+ */
+function get(k, def) {
+ var deadtime = parseInt(localStorage.getItem(prefix + k + postfix));
+ if (deadtime) {
+ if (parseInt(deadtime) < Date.parse(new Date()) / 1000) {
+ if (def) {
+ return def;
+ } else {
+ return false;
+ }
+ }
+ }
+ var res = localStorage.getItem(prefix + k);
+ if (res) {
+ return JSON.parse(res);
+ } else {
+ if (def == undefined || def == '') {
+ def = false;
+ }
+ return def;
+ }
+}
+
+function remove(k) {
+ localStorage.removeItem(prefix + k);
+ localStorage.removeItem(prefix + k + postfix);
+}
+
+/**
+ * 清理所有缓存
+ * @return {[type]} [description]
+ */
+function clear() {
+ localStorage.clear();
+}
+
+module.exports = {
+ put: put,
+ get: get,
+ remove: remove,
+ clear: clear,
+};
diff --git a/examples/utils/param.js b/examples/utils/param.js
new file mode 100644
index 0000000..f93a1d0
--- /dev/null
+++ b/examples/utils/param.js
@@ -0,0 +1,53 @@
+export const stringify = json => {
+ const urlEncode = (param, key, encode) => {
+ if (param === null) return '';
+ let paramStr = '';
+ const t = typeof param;
+ if (t === 'string' || t === 'number' || t === 'boolean') {
+ paramStr = `&${key}=${encode === null || encode ? encodeURIComponent(param) : param}`;
+ } else {
+ for (const i in param) {
+ if (i) {
+ if (param[i] !== undefined && param[i] !== '' && !(param[i] && typeof param[i] === 'string' && /^\s+$/.test(param[i]))) {
+ const k = key == null ? i : `${key}${param instanceof Array ? `[${i}]` : `.${i}`}`;
+ paramStr += urlEncode(param[i], k, encode);
+ }
+ }
+ }
+ }
+ return paramStr;
+ };
+ return urlEncode(json).substring(1);
+};
+
+export const parse = url => {
+ let obj = {}; // 创建一个Object
+ let reg = /[?&][^?&]+=[^?&]+/g; // 正则匹配 ?&开始 =拼接 非?&结束 的参数
+ let arr = url.match(reg); // match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配。
+ // arr数组形式 ['?id=12345','&a=b']
+ if (arr) {
+ arr.forEach(item => {
+ /**
+ * tempArr数组 ['id','12345']和['a','b']
+ * 第一个是key,第二个是value
+ * */
+ let tempArr = item.substring(1).split('=');
+ let key = decodeURIComponent(tempArr[0]);
+ let val = decodeURIComponent(tempArr[1]);
+ obj[key] = val;
+ });
+ }
+ return obj;
+};
+
+export const urlParam = data => {
+ return `${data ? `?${stringify(data)}` : ''}`;
+};
+
+/**
+ * 清除首尾斜杠,便于拼接字符串
+ * @param {*} str URL
+ */
+export const clear = str => {
+ return str.replace(/^(\s|\/)+|(\s|\/)+$/g, '');
+};
diff --git a/examples/utils/request.js b/examples/utils/request.js
new file mode 100644
index 0000000..53b4c67
--- /dev/null
+++ b/examples/utils/request.js
@@ -0,0 +1,34 @@
+import axios from 'axios';
+
+const request = axios.create({
+ baseURL: 'http://47.98.245.217:7070/tms-web-api/',
+ timeout: 1000 * 60,
+ withCredentials: true,
+ headers: {
+ 'Content-Type': 'application/json; charset=utf-8',
+ Authorization: 'Bearer cd355920-ff83-445e-87e1-39d7ecfb8566',
+ },
+});
+
+// respone 拦截器
+request.interceptors.response.use(
+ response => {
+ const { data = {}, config } = response;
+ const { businessException, errorCode, message, success } = data;
+ if (config && config.interceptors === false) {
+ // 请求配置不做返回拦截的情况
+ return response;
+ } else {
+ if (success) {
+ return data;
+ } else {
+ return Promise.reject(response);
+ }
+ }
+ },
+ error => {
+ return Promise.reject(error);
+ },
+);
+
+export default request;
diff --git a/examples/views/docs/component/scheme.md b/examples/views/docs/component/scheme.md
index 264d664..f06e514 100644
--- a/examples/views/docs/component/scheme.md
+++ b/examples/views/docs/component/scheme.md
@@ -10,7 +10,7 @@
```html
-
+
@@ -63,7 +63,7 @@ export default {
{ id: '8', name: '卢纳', age: 55 },
]
resolve({
- result: params.currentPage === 1 ? list.slice(0, 5) : list.slice(5),
+ result: list,
totalCount: list.length
});
}, 1500);
@@ -101,6 +101,39 @@ export default {
:::
+## 内置接口逻辑
+
+如果CURD的接口都是同一路径下,可以使用内置接口逻辑快速对接
+
+::: snippet 通过`url`配置接口路径,`http`设置Promise形式的HTTP请求库
+
+```html
+
+
+
+
+
+
+
+```
+
+:::
+
## API
## Attribute 属性
diff --git a/packages/_utils/index.js b/packages/_utils/index.js
new file mode 100644
index 0000000..710ebe1
--- /dev/null
+++ b/packages/_utils/index.js
@@ -0,0 +1,86 @@
+/**
+ * 深度克隆对象
+ * @param {Object} obj 目标对象
+ * @returns {Object} 克隆的新对象
+ */
+export const cloneDeep = obj => {
+ if (typeof obj !== 'object') {
+ return obj;
+ }
+ if (!obj) {
+ return obj;
+ }
+ if (obj instanceof Date) {
+ return new Date(obj);
+ }
+ if (obj instanceof RegExp) {
+ return new RegExp(obj);
+ }
+ if (obj instanceof Function) {
+ return obj;
+ }
+ let newObj;
+ if (obj instanceof Array) {
+ newObj = [];
+ for (let i = 0, len = obj.length; i < len; i++) {
+ newObj.push(cloneDeep(obj[i]));
+ }
+ return newObj;
+ }
+ newObj = {};
+ for (let key in obj) {
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
+ if (typeof obj[key] !== 'object') {
+ newObj[key] = obj[key];
+ } else {
+ newObj[key] = cloneDeep(obj[key]);
+ }
+ }
+ }
+ return newObj;
+};
+
+/**
+ * 对象深度取值
+ * @desctiption 来源于"typy.js"中src/util的getNestedObject函数
+ * @param {Object} obj 目标对象
+ * @param {String} dotSeparatedKeys 用分隔符".", "[", "]", "'", """隔开的取值路径
+ * @example get({ a: { b: { c: ['d'] } } }, 'a.b.c.0')
+ */
+export const get = (obj, dotSeparatedKeys) => {
+ if (dotSeparatedKeys !== undefined && typeof dotSeparatedKeys !== 'string') return undefined;
+ if (typeof obj !== 'undefined' && typeof dotSeparatedKeys === 'string') {
+ // eslint-disable-next-line no-useless-escape
+ const splitRegex = /[.\[\]'"]/g;
+ const pathArr = dotSeparatedKeys.split(splitRegex).filter(k => k !== '');
+ obj = pathArr.reduce((o, key) => (o && o[key] !== undefined ? o[key] : undefined), obj);
+ }
+ return obj;
+};
+
+/**
+ * 对象深度赋值
+ * @description 改写自get方法
+ * @param {Object} obj 目标对像
+ * @param {String} dotSeparatedKeys 用分隔符".", "[", "]", "'", """隔开的赋值路径
+ * @param {*} value 目标值
+ * @example set(obj, 'a.b.c', 'd')
+ */
+export const set = (obj, dotSeparatedKeys, value) => {
+ // eslint-disable-next-line no-useless-escape
+ const splitRegex = /[.\[\]'"]/g;
+ const pathArr = dotSeparatedKeys.split(splitRegex).filter(k => k !== '');
+ const key = pathArr.pop();
+ pathArr.reduce((o, k) => {
+ if ((o && o[k] === undefined) || o[k] === null) {
+ o[k] = !isNaN(Number(key)) ? [] : {};
+ }
+ return o[k];
+ }, obj)[key] = value;
+};
+
+export default {
+ cloneDeep,
+ get,
+ set,
+};
diff --git a/packages/_utils/param.js b/packages/_utils/param.js
new file mode 100644
index 0000000..f93a1d0
--- /dev/null
+++ b/packages/_utils/param.js
@@ -0,0 +1,53 @@
+export const stringify = json => {
+ const urlEncode = (param, key, encode) => {
+ if (param === null) return '';
+ let paramStr = '';
+ const t = typeof param;
+ if (t === 'string' || t === 'number' || t === 'boolean') {
+ paramStr = `&${key}=${encode === null || encode ? encodeURIComponent(param) : param}`;
+ } else {
+ for (const i in param) {
+ if (i) {
+ if (param[i] !== undefined && param[i] !== '' && !(param[i] && typeof param[i] === 'string' && /^\s+$/.test(param[i]))) {
+ const k = key == null ? i : `${key}${param instanceof Array ? `[${i}]` : `.${i}`}`;
+ paramStr += urlEncode(param[i], k, encode);
+ }
+ }
+ }
+ }
+ return paramStr;
+ };
+ return urlEncode(json).substring(1);
+};
+
+export const parse = url => {
+ let obj = {}; // 创建一个Object
+ let reg = /[?&][^?&]+=[^?&]+/g; // 正则匹配 ?&开始 =拼接 非?&结束 的参数
+ let arr = url.match(reg); // match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配。
+ // arr数组形式 ['?id=12345','&a=b']
+ if (arr) {
+ arr.forEach(item => {
+ /**
+ * tempArr数组 ['id','12345']和['a','b']
+ * 第一个是key,第二个是value
+ * */
+ let tempArr = item.substring(1).split('=');
+ let key = decodeURIComponent(tempArr[0]);
+ let val = decodeURIComponent(tempArr[1]);
+ obj[key] = val;
+ });
+ }
+ return obj;
+};
+
+export const urlParam = data => {
+ return `${data ? `?${stringify(data)}` : ''}`;
+};
+
+/**
+ * 清除首尾斜杠,便于拼接字符串
+ * @param {*} str URL
+ */
+export const clear = str => {
+ return str.replace(/^(\s|\/)+|(\s|\/)+$/g, '');
+};
diff --git a/packages/form/form-render.vue b/packages/form/form-render.vue
index 76365a2..e07092d 100644
--- a/packages/form/form-render.vue
+++ b/packages/form/form-render.vue
@@ -36,46 +36,49 @@
-
-
-
-
-
-
+
+
+
+
+
- onInput({ value: v, item })"
- v-on="bindItemEvent(item)"
- v-bind="item.props"
- :style="item.style || { maxWidth: '100%' }"
- >
-
-
-
+ })
+ "
+ >
+ onInput({ value: v, item })"
+ v-on="bindItemEvent(item)"
+ v-bind="item.props"
+ :style="item.style || { maxWidth: '100%' }"
+ >
+
+
+
+
@@ -190,6 +193,19 @@ export default {
return undefined;
}
},
+ /**
+ * @description 绑定表单项显示状态
+ * @param {Object} item 表单项配置
+ * @param {String} type Vue显示类型,可选值:visible、show
+ * @returns {Boolean} 显示状态
+ */
+ bindItemVisible(item, type) {
+ const visible = item[type];
+ if (typeof visible === 'function') {
+ return visible(this.model);
+ }
+ return item[type] !== false;
+ },
},
};
diff --git a/packages/form/index.vue b/packages/form/index.vue
index cff0547..e5c2db4 100644
--- a/packages/form/index.vue
+++ b/packages/form/index.vue
@@ -39,7 +39,7 @@