mirror of https://gitee.com/stylefeng/guns
【dict】【gunsSelect】通用组件封装
parent
94d179557c
commit
4e653f9897
|
@ -150,7 +150,9 @@ layui.config({
|
||||||
ztree: '../../expand/module/ztree/ztree-object',
|
ztree: '../../expand/module/ztree/ztree-object',
|
||||||
HttpRequest: '../../expand/module/HttpRequest/HttpRequest',
|
HttpRequest: '../../expand/module/HttpRequest/HttpRequest',
|
||||||
func: '../../expand/module/func/func',
|
func: '../../expand/module/func/func',
|
||||||
dict: '../../expand/module/dict/dict'
|
dict: '../../expand/module/dict/dict',
|
||||||
|
gunsSelect: '../../expand/module/gunsSelect/gunsSelect'
|
||||||
|
|
||||||
}).use(['layer', 'admin'], function () {
|
}).use(['layer', 'admin'], function () {
|
||||||
var $ = layui.jquery;
|
var $ = layui.jquery;
|
||||||
var layer = layui.layer;
|
var layer = layui.layer;
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
/**
|
||||||
|
* 基于xmSelect封装字典通用下拉选项
|
||||||
|
* v1.0
|
||||||
|
* @author 陈金龙
|
||||||
|
* @date 2021/1/25 10:59
|
||||||
|
*/
|
||||||
|
|
||||||
layui.define(['jquery', 'HttpRequest', 'xmSelect'], function (exports) {
|
layui.define(['jquery', 'HttpRequest', 'xmSelect'], function (exports) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var dict = function () {
|
var dict = function () {
|
||||||
|
|
|
@ -4,8 +4,12 @@
|
||||||
2.引入layui 模块组件'dict'
|
2.引入layui 模块组件'dict'
|
||||||
layui.use(['dict'], function () {
|
layui.use(['dict'], function () {
|
||||||
|
|
||||||
3.渲染组件
|
var dict = layui.dict;
|
||||||
dict.render({
|
// 渲染组件
|
||||||
elem: '#demo2', //控件
|
dict.render({
|
||||||
code: '' //字典dictTypeCode
|
elem: '#demo2', //控件
|
||||||
});
|
code: '' //字典dictTypeCode
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
/**
|
||||||
|
* 封装通用选择组件
|
||||||
|
*
|
||||||
|
* v1.0
|
||||||
|
* 目前仅支持下拉框
|
||||||
|
*
|
||||||
|
* @author 陈金龙
|
||||||
|
* @date 2021/1/25 10:59
|
||||||
|
*/
|
||||||
|
layui.define(['jquery', 'HttpRequest', 'xmSelect', 'form'], function (exports) {
|
||||||
|
"use strict";
|
||||||
|
var gunsSelect = function () {
|
||||||
|
this.v = '1.0';
|
||||||
|
},
|
||||||
|
$ = layui.$,
|
||||||
|
HttpRequest = layui.HttpRequest,
|
||||||
|
form = layui.form;
|
||||||
|
|
||||||
|
gunsSelect.prototype.render = function (options) {
|
||||||
|
|
||||||
|
var opts = options,
|
||||||
|
url = opts.url,
|
||||||
|
method = opts.method || 'get',
|
||||||
|
where = opts.where,
|
||||||
|
fields = opts.fields || {name: 'name', value: 'value'},
|
||||||
|
elem = opts.elem;
|
||||||
|
//渲染 <input type="checkbox" name="like[write]" title="写作">
|
||||||
|
//渲染 <input type="radio" name="sex" value="男" title="男">
|
||||||
|
|
||||||
|
var a = {
|
||||||
|
init: function () {
|
||||||
|
new HttpRequest(url, method, function (obj) {
|
||||||
|
for (var i = 0; i < obj.data.length; i++) {
|
||||||
|
$(elem).append('<option value="' + common.get(obj.data[i], fields.value) + '">' + common.get(obj.data[i], fields.name) + '</option>');
|
||||||
|
}
|
||||||
|
form.render();
|
||||||
|
}, function (data) {
|
||||||
|
}).set(where).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var common = {
|
||||||
|
get: function (obj, key) {
|
||||||
|
return obj[key];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
a.init();
|
||||||
|
return new gunsSelect();
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
exports('gunsSelect', new gunsSelect());
|
||||||
|
});
|
|
@ -0,0 +1,17 @@
|
||||||
|
1.添加html标签
|
||||||
|
<select name="city" id="city" lay-verify="" lay-search>
|
||||||
|
<option value="">请选择</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
2.引入layui 模块组件'dict'
|
||||||
|
layui.use(['gunsSelect'], function () {
|
||||||
|
var gunsSelect = layui.gunsSelect;
|
||||||
|
// 渲染组件
|
||||||
|
gunsSelect.render({
|
||||||
|
url: Feng.ctxPath + '/dict/getDictList',
|
||||||
|
elem: '#city',
|
||||||
|
fields: {name: 'dictName', value: 'dictCode'},
|
||||||
|
where:{code:123}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue