el-crud-page 1.0.0

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.
@@ -0,0 +1,129 @@
1
+ var toString = Object.prototype.toString;
2
+
3
+ export default function kindOf(val) {
4
+ if (val === void 0) return 'undefined';
5
+ if (val === null) return 'null';
6
+
7
+ var type = typeof val;
8
+ if (type === 'boolean') return 'boolean';
9
+ if (type === 'string') return 'string';
10
+ if (type === 'number') return 'number';
11
+ if (type === 'symbol') return 'symbol';
12
+ if (type === 'function') {
13
+ return isGeneratorFn(val) ? 'generatorfunction' : 'function';
14
+ }
15
+
16
+ if (isArray(val)) return 'array';
17
+ if (isBuffer(val)) return 'buffer';
18
+ if (isArguments(val)) return 'arguments';
19
+ if (isDate(val)) return 'date';
20
+ if (isError(val)) return 'error';
21
+ if (isRegexp(val)) return 'regexp';
22
+
23
+ switch (ctorName(val)) {
24
+ case 'Symbol': return 'symbol';
25
+ case 'Promise': return 'promise';
26
+
27
+ // Set, Map, WeakSet, WeakMap
28
+ case 'WeakMap': return 'weakmap';
29
+ case 'WeakSet': return 'weakset';
30
+ case 'Map': return 'map';
31
+ case 'Set': return 'set';
32
+
33
+ // 8-bit typed arrays
34
+ case 'Int8Array': return 'int8array';
35
+ case 'Uint8Array': return 'uint8array';
36
+ case 'Uint8ClampedArray': return 'uint8clampedarray';
37
+
38
+ // 16-bit typed arrays
39
+ case 'Int16Array': return 'int16array';
40
+ case 'Uint16Array': return 'uint16array';
41
+
42
+ // 32-bit typed arrays
43
+ case 'Int32Array': return 'int32array';
44
+ case 'Uint32Array': return 'uint32array';
45
+ case 'Float32Array': return 'float32array';
46
+ case 'Float64Array': return 'float64array';
47
+ }
48
+
49
+ if (isGeneratorObj(val)) {
50
+ return 'generator';
51
+ }
52
+
53
+ // Non-plain objects
54
+ type = toString.call(val);
55
+ switch (type) {
56
+ case '[object Object]': return 'object';
57
+ // iterators
58
+ case '[object Map Iterator]': return 'mapiterator';
59
+ case '[object Set Iterator]': return 'setiterator';
60
+ case '[object String Iterator]': return 'stringiterator';
61
+ case '[object Array Iterator]': return 'arrayiterator';
62
+ }
63
+
64
+ // other
65
+ return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
66
+ };
67
+
68
+ function ctorName(val) {
69
+ return typeof val.constructor === 'function' ? val.constructor.name : null;
70
+ }
71
+
72
+ function isArray(val) {
73
+ if (Array.isArray) return Array.isArray(val);
74
+ return val instanceof Array;
75
+ }
76
+
77
+ function isError(val) {
78
+ return val instanceof Error || (typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number');
79
+ }
80
+
81
+ function isDate(val) {
82
+ if (val instanceof Date) return true;
83
+ return typeof val.toDateString === 'function'
84
+ && typeof val.getDate === 'function'
85
+ && typeof val.setDate === 'function';
86
+ }
87
+
88
+ function isRegexp(val) {
89
+ if (val instanceof RegExp) return true;
90
+ return typeof val.flags === 'string'
91
+ && typeof val.ignoreCase === 'boolean'
92
+ && typeof val.multiline === 'boolean'
93
+ && typeof val.global === 'boolean';
94
+ }
95
+
96
+ function isGeneratorFn(name, val) {
97
+ return ctorName(name) === 'GeneratorFunction';
98
+ }
99
+
100
+ function isGeneratorObj(val) {
101
+ return typeof val.throw === 'function'
102
+ && typeof val.return === 'function'
103
+ && typeof val.next === 'function';
104
+ }
105
+
106
+ function isArguments(val) {
107
+ try {
108
+ if (typeof val.length === 'number' && typeof val.callee === 'function') {
109
+ return true;
110
+ }
111
+ } catch (err) {
112
+ if (err.message.indexOf('callee') !== -1) {
113
+ return true;
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+
119
+ /**
120
+ * If you need to support Safari 5-7 (8-10 yr-old browser),
121
+ * take a look at https://github.com/feross/is-buffer
122
+ */
123
+
124
+ function isBuffer(val) {
125
+ if (val.constructor && typeof val.constructor.isBuffer === 'function') {
126
+ return val.constructor.isBuffer(val);
127
+ }
128
+ return false;
129
+ }
@@ -0,0 +1,29 @@
1
+ import { isString, isBoolean, isFunction } from "./index";
2
+
3
+ /**
4
+ * 解析 hidden 参数的几个场景
5
+ * 1 Boolean
6
+ * 2 Function({ scope })
7
+ * 3 :[prop] is bind form[prop] value
8
+ * @param {*} value
9
+ */
10
+ export default function (method, { value, scope, data = {} }) {
11
+ if (method === "hidden") {
12
+ if (isBoolean(value)) {
13
+ return value;
14
+ } else if (isString(value)) {
15
+ const prop = value.substring(1, value.length);
16
+
17
+ switch (value[0]) {
18
+ case "@":
19
+ return !scope[prop];
20
+ case ":":
21
+ return data[prop];
22
+ }
23
+ } else if (isFunction(value)) {
24
+ return value({ scope, ...data });
25
+ }
26
+
27
+ return false;
28
+ }
29
+ }
@@ -0,0 +1,58 @@
1
+ Math.easeInOutQuad = function(t, b, c, d) {
2
+ t /= d / 2
3
+ if (t < 1) {
4
+ return c / 2 * t * t + b
5
+ }
6
+ t--
7
+ return -c / 2 * (t * (t - 2) - 1) + b
8
+ }
9
+
10
+ // requestAnimationFrame for Smart Animating http://goo.gl/sx5sts
11
+ var requestAnimFrame = (function() {
12
+ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / 60) }
13
+ })()
14
+
15
+ /**
16
+ * Because it's so fucking difficult to detect the scrolling element, just move them all
17
+ * @param {number} amount
18
+ */
19
+ function move(amount) {
20
+ document.documentElement.scrollTop = amount
21
+ document.body.parentNode.scrollTop = amount
22
+ document.body.scrollTop = amount
23
+ }
24
+
25
+ function position() {
26
+ return document.documentElement.scrollTop || document.body.parentNode.scrollTop || document.body.scrollTop
27
+ }
28
+
29
+ /**
30
+ * @param {number} to
31
+ * @param {number} duration
32
+ * @param {Function} callback
33
+ */
34
+ export function scrollTo(to, duration, callback) {
35
+ const start = position()
36
+ const change = to - start
37
+ const increment = 20
38
+ let currentTime = 0
39
+ duration = (typeof (duration) === 'undefined') ? 500 : duration
40
+ var animateScroll = function() {
41
+ // increment the time
42
+ currentTime += increment
43
+ // find the value with the quadratic in-out easing function
44
+ var val = Math.easeInOutQuad(currentTime, start, change, duration)
45
+ // move the document.body
46
+ move(val)
47
+ // do the animation unless its over
48
+ if (currentTime < duration) {
49
+ requestAnimFrame(animateScroll)
50
+ } else {
51
+ if (callback && typeof (callback) === 'function') {
52
+ // the animation is done so lets callback
53
+ callback()
54
+ }
55
+ }
56
+ }
57
+ animateScroll()
58
+ }
@@ -0,0 +1,79 @@
1
+ /*!
2
+ * shallow-clone <https://github.com/jonschlinkert/shallow-clone>
3
+ *
4
+ * Copyright (c) 2015-present, Jon Schlinkert.
5
+ * Released under the MIT License.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ import typeOf from "./kind-of";
11
+
12
+ const valueOf = Symbol.prototype.valueOf;
13
+
14
+ export default function clone(val, deep) {
15
+ switch (typeOf(val)) {
16
+ case 'array':
17
+ return val.slice();
18
+ case 'object':
19
+ return Object.assign({}, val);
20
+ case 'date':
21
+ return new val.constructor(Number(val));
22
+ case 'map':
23
+ return new Map(val);
24
+ case 'set':
25
+ return new Set(val);
26
+ case 'buffer':
27
+ return cloneBuffer(val);
28
+ case 'symbol':
29
+ return cloneSymbol(val);
30
+ case 'arraybuffer':
31
+ return cloneArrayBuffer(val);
32
+ case 'float32array':
33
+ case 'float64array':
34
+ case 'int16array':
35
+ case 'int32array':
36
+ case 'int8array':
37
+ case 'uint16array':
38
+ case 'uint32array':
39
+ case 'uint8clampedarray':
40
+ case 'uint8array':
41
+ return cloneTypedArray(val);
42
+ case 'regexp':
43
+ return cloneRegExp(val);
44
+ case 'error':
45
+ return Object.create(val);
46
+ default: {
47
+ return val;
48
+ }
49
+ }
50
+ }
51
+
52
+ function cloneRegExp(val) {
53
+ const flags = val.flags !== void 0 ? val.flags : (/\w+$/.exec(val) || void 0);
54
+ const re = new val.constructor(val.source, flags);
55
+ re.lastIndex = val.lastIndex;
56
+ return re;
57
+ }
58
+
59
+ function cloneArrayBuffer(val) {
60
+ const res = new val.constructor(val.byteLength);
61
+ new Uint8Array(res).set(new Uint8Array(val));
62
+ return res;
63
+ }
64
+
65
+ function cloneTypedArray(val, deep) {
66
+ return new val.constructor(val.buffer, val.byteOffset, val.length);
67
+ }
68
+
69
+ function cloneBuffer(val) {
70
+ const len = val.length;
71
+ const buf = Buffer.allocUnsafe ? Buffer.allocUnsafe(len) : Buffer.from(len);
72
+ val.copy(buf);
73
+ return buf;
74
+ }
75
+
76
+ function cloneSymbol(val) {
77
+ return valueOf ? Object(valueOf.call(val)) : {};
78
+ }
79
+
@@ -0,0 +1,97 @@
1
+ import { isArray, isFunction, isObject, isString } from "./index";
2
+
3
+ export const format = {
4
+ number(value) {
5
+ let result
6
+ if( isArray(value) ){
7
+ result = value.map(Number).map(item => isNaN(item) ? undefined : item)
8
+ }else{
9
+ result = Number(value)
10
+ if(isNaN(result)){
11
+ result = undefined
12
+ }
13
+ }
14
+ return result
15
+
16
+ },
17
+ string(value) {
18
+ return isArray(value) ? value.map(String) : String(value);
19
+ },
20
+ split(value) {
21
+ return isString(value) ? value.split(",").filter(Boolean) : value;
22
+ },
23
+ join(value) {
24
+ return isArray(value) ? value.join(",") : value;
25
+ },
26
+ boolean(value) {
27
+ return Boolean(value);
28
+ },
29
+ booleanNumber(value) {
30
+ return Boolean(value) ? 1 : 0;
31
+ },
32
+ datetimerange(value, form, method) {
33
+ if (method == "bind") {
34
+ return [form.startTime, form.endTime];
35
+ } else {
36
+ const [startTime, endTime] = value || [];
37
+ form.startTime = startTime;
38
+ form.endTime = endTime;
39
+ return undefined;
40
+ }
41
+ },
42
+ splitJoin(value, _, method) {
43
+ if (method == "bind") {
44
+ return isString(value) ? value.split(",").filter(Boolean) : value;
45
+ } else {
46
+ return isArray(value) ? value.join(",") : value;
47
+ }
48
+ }
49
+ };
50
+
51
+ function parse(method, { value, pipe, form }) {
52
+ if (!pipe) {
53
+ return value;
54
+ }
55
+
56
+ let pipes = [];
57
+
58
+ if (isString(pipe)) {
59
+ if (format[pipe]) {
60
+ pipes = [pipe];
61
+ } else {
62
+ console.error(`${pipe} is not found.`);
63
+ return value;
64
+ }
65
+ } else if (isArray(pipe)) {
66
+ pipes = pipe;
67
+ } else if (isObject(pipe)) {
68
+ pipes = isArray(pipe[method]) ? pipe[method] : [pipe[method]];
69
+ } else if (isFunction(pipe)) {
70
+ pipes = [pipe];
71
+ } else {
72
+ console.error(`Hook data error!`);
73
+ return value;
74
+ }
75
+
76
+ let d = value;
77
+
78
+ pipes.forEach((e) => {
79
+ if (isString(e)) {
80
+ d = format[e](d, form, method);
81
+ } else if (isFunction(e)) {
82
+ d = e(d, form);
83
+ }
84
+ });
85
+
86
+ return d;
87
+ }
88
+
89
+ export default {
90
+ bind(value, pipe, form) {
91
+ return parse("bind", { value, pipe, form });
92
+ },
93
+
94
+ submit(value, pipe, form) {
95
+ return parse("submit", { value, pipe, form });
96
+ }
97
+ };
@@ -0,0 +1,215 @@
1
+ import { isFunction, isString, cloneDeep, isObject } from "./index";
2
+ import Vue from "vue";
3
+
4
+ // ...删除固定创建的 __inst ...
5
+ const __vue = Vue // Vue
6
+
7
+ /**
8
+ * Parse JSX, filter params
9
+ * options 增加 inst 参数,代表外部传入的 Vue 实例
10
+ * @param {*} vnode
11
+ * @param {{inst, scope, prop, children, $scopedSlots}} options
12
+ */
13
+ const parse_jsx = (vnode, options = {}) => {
14
+ const { inst, scope, prop, $scopedSlots, children = [] } = options;
15
+ const h = inst.$createElement;
16
+
17
+ if (vnode.name.indexOf("slot-") == 0) {
18
+ let rn = $scopedSlots[vnode.name];
19
+
20
+ if (rn) {
21
+ return rn({ scope });
22
+ } else {
23
+ return "错误";
24
+ }
25
+ }
26
+
27
+ if (vnode.render) {
28
+ if (!inst.$root.$options.components[vnode.name]) {
29
+ __vue.component(vnode.name, cloneDeep(vnode));
30
+ }
31
+
32
+ // Avoid props prompts { type:null }
33
+ delete vnode.props;
34
+ }
35
+
36
+ const keys = [
37
+ "class",
38
+ "style",
39
+ "props",
40
+ "attrs",
41
+ "domProps",
42
+ "on",
43
+ "nativeOn",
44
+ "directives",
45
+ "scopedSlots",
46
+ "slot",
47
+ "key",
48
+ "ref",
49
+ "refInFor"
50
+ ];
51
+
52
+ // Avoid loop update
53
+ let data = cloneDeep(vnode);
54
+
55
+ for (let i in data) {
56
+ if (!keys.includes(i)) {
57
+ delete data[i];
58
+ }
59
+ }
60
+
61
+ if (scope) {
62
+ if (!data.attrs) {
63
+ data.attrs = {};
64
+ }
65
+
66
+ if (!data.on) {
67
+ data.on = {};
68
+ }
69
+
70
+ if (!data.props) {
71
+ data.props = {};
72
+ }
73
+
74
+ // 添加作用域
75
+ data.props.scope = scope
76
+
77
+ // 输入事件
78
+ const onInput = data.on.input
79
+
80
+ // 设置默认值
81
+ data.attrs.value = scope[prop];
82
+
83
+ // 监听输入事件
84
+ data.on.input = (val) => {
85
+ inst.$set(scope, prop, val);
86
+ if (onInput) {
87
+ onInput(val)
88
+ }
89
+ };
90
+ }
91
+ return h(vnode.name, cloneDeep(data), children);
92
+ };
93
+
94
+ /**
95
+ * Render vNode
96
+ * options 允许 inst 为空,通过调用者的 this 获取 Vue 实例
97
+ * @param {*} vnode
98
+ * @param {{inst?, prop, scope, $scopedSlots}} options
99
+ */
100
+ export function renderNode(vnode, options) {
101
+ // 如果 options.inst 为空,则尝试用调用者上下文的 this
102
+ const { prop, scope, $scopedSlots } = options;
103
+ const inst = options.inst || this;
104
+ const h = inst.$createElement;
105
+
106
+ if (!vnode) {
107
+ return null;
108
+ }
109
+
110
+ // When slot or tagName
111
+ if (isString(vnode)) {
112
+ return parse_jsx({ name: vnode }, { inst,prop, scope, $scopedSlots });
113
+ }
114
+
115
+ // When customeize render function
116
+ if (isFunction(vnode)) {
117
+ return vnode({ scope, h });
118
+ }
119
+ // When jsx
120
+ if (isObject(vnode)) {
121
+ if( isObject( vnode.name ) ){
122
+ let component = vnode.name
123
+ let curComponent = Object.values(inst.$options.components).find(item=>item == vnode)
124
+ if( curComponent ){
125
+ vnode.name = curComponent.name ;
126
+ }else{
127
+ const componentName = component.name || "component_" + Math.random().toString(36).substr(2, 9);
128
+ inst.$options.components[ componentName ] = component;
129
+ vnode.name = componentName;
130
+ console.log( componentName )
131
+ }
132
+ }
133
+
134
+ if (vnode.context) {
135
+ return vnode;
136
+ }
137
+
138
+ if (vnode.name) {
139
+ // Handle general component
140
+ const keys = ["el-select", "el-radio-group", "el-checkbox-group"];
141
+ if (keys.includes(vnode.name)) {
142
+ let options = vnode.options;
143
+ if( isFunction( options ) ){
144
+ options = options( scope );
145
+ }
146
+
147
+ // Append component children
148
+ const children = (options || []).map((e, i) => {
149
+ if (vnode.name === "el-select") {
150
+ let label, value;
151
+
152
+ if (isString(e)) {
153
+ label = value = e;
154
+ } else if (isObject(e)) {
155
+ label = e.label;
156
+ value = e.value;
157
+ } else {
158
+ return "错误";
159
+ }
160
+
161
+ return (
162
+ <el-option
163
+ {...{
164
+ props: {
165
+ key: i,
166
+ label,
167
+ value,
168
+ ...e.props
169
+ }
170
+ }}
171
+ />
172
+ );
173
+ } else if (vnode.name === "el-radio-group") {
174
+ return (
175
+ <el-radio
176
+ {...{
177
+ props: {
178
+ key: i,
179
+ label: e.value,
180
+ ...e.props
181
+ }
182
+ }}>
183
+ {e.label}
184
+ </el-radio>
185
+ );
186
+ } else if (vnode.name === "el-checkbox-group") {
187
+ if( typeof scope[prop]==='undefined' ){
188
+ inst.$set(scope, prop, [])
189
+ }
190
+
191
+ return (
192
+ <el-checkbox
193
+ {...{
194
+ props: {
195
+ key: i,
196
+ label: e.value,
197
+ ...e.props
198
+ }
199
+ }}>
200
+ {e.label}
201
+ </el-checkbox>
202
+ );
203
+ } else {
204
+ return null;
205
+ }
206
+ });
207
+ return parse_jsx(vnode, { inst, prop, scope, children });
208
+ } else {
209
+ return parse_jsx(vnode, { inst, prop, scope, $scopedSlots });
210
+ }
211
+ } else {
212
+ return "错误";
213
+ }
214
+ }
215
+ }