wangrong
2025-09-23 40634ebaf5863a599bba8ca2c0575ca079fb8e15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/**
 * UI v1.1.0
 * Copyright 2017-2018 Muyao
 * Licensed under the Muyao License 1.0 
 */
(function (window, document, $) {
    'use strict';
    
    // 项目名称
    $.ctx = location.pathname.substring(0,location.pathname.lastIndexOf("/")+1);
    
 
    // 获取颜色配置信息
    $.colors = function (name, level) {
        if (!$.configs.colors && typeof $.configs.colors[name] === 'undefined') {
            return null;
        }
 
        if (level && typeof $.configs.colors[name][level] !== 'undefined') {
            return $.configs.colors[name][level];
        } else {
            return $.configs.colors[name];
        }
    };
 
    // 3rd调用参数
    $.po = function (name, options) {
        var defaults = $.components.getDefaults(name);
        return $.extend(true, {}, defaults, options);
    };
 
    // 配置信息存储管理
    $.configs = $.configs || {};
 
    $.extend($.configs, {
        _data: {},
        get: function () {
            var data = this._data, name,
                _argLen = arguments.length;
 
            if (_argLen === 0) {
                return;
            }
            for (var i = 0; i < _argLen; i++) {
                name = arguments[i];
 
                data = data[name];
            }
 
            return data;
        },
        set: function (name, value) {
            if (this.get(name)) {
                console.error('configs:' + name + '对象已经存在了');
            } else {
                this._data[name] = value;
            }
        },
        extend: function (name, options) {
            return $.extend(true, this.get(name), options);
        }
    });
 
    // 实现插件的提前检测和调用
    $.components = $.components || {};
 
    $.extend($.components, {
        _components: {},
        register: function (name, obj) {
            this._components[name] = obj;
        },
        init: function (context, iframe, name, args) {
            var self = this, obj;
            args = args || true;
 
            if (typeof name === 'undefined') {
                $.each(this._components, function (name) {
                    self.init(context, iframe, name, args);
                });
            } else {
                context = context || document;
 
                obj = this.get(name);
 
                if (!obj) {
                    return;
                }
 
                switch (obj.mode) {
                    case 'default':
                        return this._initDefault(name, context, iframe);
                    case 'init':
                        return this._initComponent(obj, context, iframe);
                    case 'api':
                        return this._initApi(obj, context, args, iframe);
                    default:
                        this._initApi(obj, context, args, iframe);
                        this._initComponent(obj, context, iframe);
                        return;
                }
            }
        },
        _initDefault: function (name, context, iframe) { // jquery 3rd的基本用法
            var iframe$ = iframe ? iframe.$ : $, defaults;
 
            if (!iframe$.fn[name]) {
                return;
            }
 
            defaults = this.getDefaults(name);
 
            $('[data-plugin=' + name + ']', context).each(function () {
                var $this = iframe$(this),
                    options = $.extend(true, {}, defaults, $this.data());
 
                $this[name](options);
            });
        },
        _initComponent: function (obj, context, iframe) { // jquery 3rd的高级用法
            if ($.isFunction(obj.init)) {
                obj.init.call(obj, context, iframe);
            }
        },
        _initApi: function (obj, context, args, iframe) { // 其他处理
            if (args && $.isFunction(obj.api)) {
                obj.api.call(obj, context, iframe);
            }
        },
        getDefaults: function (name) {
            var component = this.get(name);
 
            return component && typeof component.defaults !== "undefined" ? component.defaults : {};
        },
        get: function (name) {
            if (typeof this._components[name] !== "undefined") {
                return this._components[name];
            } else {
                console.error('component:' + name + ' 脚本文件没有注册任何信息!');
                return undefined;
            }
        }
    });
 
    // 本地存储对象操作 localStorage
    $.storage = $.storage || {};
 
    $.extend($.storage, {
        set: function (key, value, time) { //存入缓存
            var cacheExpireDate, cacheVal;
 
            if (!localStorage) {
                console.error('该浏览器不支持localStorage对象');
            }
 
            if (!key || !value) {
                return null;
            }
 
            // 定时情况
            if (!time || isNaN(time)) {
                cacheExpireDate = null;
            } else {
                cacheExpireDate = (new Date() - 1) + time * 1000 * 60;
            }
 
            cacheVal = {val: value, exp: cacheExpireDate};
 
            if (typeof value === "object") {
                cacheVal = JSON.stringify(cacheVal);
            }
 
            localStorage.setItem(key, cacheVal);
        },
        get: function (key) { // 获取存储内容
            var value, now, exp;
 
            if (!localStorage) {
                console.error('该浏览器不支持localStorage对象');
            }
 
            value = localStorage.getItem(key);
 
            if (!value) {
                return null;
            }
 
            if (typeof value === 'string') {
                value = JSON.parse(value);
            }
 
            now = new Date() - 1;
            exp = value.exp;
 
            if (exp && now > exp) { // 缓存内容已过期
                this.remove(key);
                return null;
            }
 
            return value.val;
        },
        remove: function (key) { // 删除指定缓存
            if (!localStorage) {
                console.error('该浏览器不支持localStorage对象');
            }
 
            localStorage.removeItem(key);
        }
    });
 
    // 本地存储对象操作 sessionStorage
    $.sessionStorage = $.sessionStorage || {};
 
    $.extend($.sessionStorage, {
        set: function (key, value) { //存入缓存
            if (!sessionStorage) {
                console.error('该浏览器不支持sessionStorage对象');
            }
 
            if (!key || !value) {
                return null;
            }
 
            if (typeof value === "object") {
                value = JSON.stringify(value);
            }
 
            sessionStorage.setItem(key, value);
        },
        get: function (key) { // 获取存储内容
            var value;
 
            if (!sessionStorage) {
                console.error('该浏览器不支持sessionStorage对象');
            }
 
            value = sessionStorage.getItem(key);
 
            if (!value) {
                return null;
            }
 
            if (typeof value === 'string') {
                value = JSON.parse(value);
            }
 
            return value;
        },
        remove: function (key) { // 删除指定缓存
            if (!sessionStorage) {
                console.error('该浏览器不支持sessionStorage对象');
            }
 
            sessionStorage.removeItem(key);
        }
    });
 
    // 网站基础设置
    $.site = $.site || {};
 
    function dataAttr(elem, key, data, iJquery) {
        var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
            rmultiDash = /([A-Z])/g;
 
        // If nothing was found internally, try to fetch any
        // data from the HTML5 data-* attribute
        if (data === undefined && elem.nodeType === 1) {
 
            var name = "data-" + key.replace(rmultiDash, "-$1").toLowerCase();
 
            data = elem.getAttribute(name);
 
            if (typeof data === "string") {
                try {
                    data = data === "true" ? true :
                        data === "false" ? false :
                            data === "null" ? null :
 
                                // Only convert to a number if it doesn't change the string
                                +data + "" === data ? +data :
                                    rbrace.test(data) ? $.parseJSON(data) :
                                        data;
                } catch (e) {
                }
 
                // Make sure we set the data so it isn't changed later
                iJquery.data(elem, key, data);
 
            } else {
                data = undefined;
            }
        }
 
        return data;
    }
 
    $.fn.extend({
        data: function (key, value, iJquery) {
            var i, name, data,
                elem = this[0],
                attrs = elem && elem.attributes;
 
            // Special expections of .data basically thwart jQuery.access,
            // so implement the relevant behavior ourselves
 
            // Gets all values
            if (key === undefined || $.isFunction(key)) {
                iJquery = key || $;
 
                if (this.length) {
                    data = iJquery.data(elem);
 
                    if (elem.nodeType === 1 && !iJquery._data(elem, "parsedAttrs")) {
                        i = attrs.length;
                        while (i--) {
 
                            // Support: IE11+
                            // The attrs elements can be null (#14894)
                            if (attrs[i]) {
                                name = attrs[i].name;
                                if (name.indexOf("data-") === 0) {
                                    name = iJquery.camelCase(name.slice(5));
                                    dataAttr(elem, name, data[name], iJquery);
                                }
                            }
                        }
                        iJquery._data(elem, "parsedAttrs", true);
                    }
                }
 
                return data;
            }
 
            if($.isFunction(value) && value.fn.jquery){
                return elem ? dataAttr(elem, key, value.data(elem, key), value) : undefined;
            }
 
            // Sets multiple values
            if (typeof key === "object") {
                return this.each(function () {
                    value && value.data(this, key);
                });
            }
 
            iJquery = iJquery || $;
 
            return arguments.length > 1 ?
 
                // Sets one value
                this.each(function () {
                    iJquery.data(this, key, value);
                }) :
 
                // Gets one value
                // Try to fetch any internally stored data first
                elem ? dataAttr(elem, key, iJquery.data(elem, key), iJquery) : undefined;
        }
    });
 
})(window, document, jQuery);