【dict】封装字典下拉框组件

pull/65/head
chenjinlong 4 years ago
parent 5389813ac2
commit dc7b93e9b1

@ -149,7 +149,8 @@ layui.config({
iconPicker: '../../expand/module/iconPicker/iconPicker',
ztree: '../../expand/module/ztree/ztree-object',
HttpRequest: '../../expand/module/HttpRequest/HttpRequest',
func: '../../expand/module/func/func'
func: '../../expand/module/func/func',
dict: '../../expand/module/dict/dict'
}).use(['layer', 'admin'], function () {
var $ = layui.jquery;
var layer = layui.layer;

@ -0,0 +1,37 @@
layui.define(['jquery', 'HttpRequest', 'xmSelect'], function (exports) {
"use strict";
var dict = function () {
this.v = '1.0';
},
$ = layui.$,
HttpRequest = layui.HttpRequest,
xmSelect = layui.xmSelect;
dict.prototype.render = function (options) {
var opts = options,
url = opts.url || Feng.ctxPath + '/dict/getDictList',
method = opts.method || 'get',
code = opts.code,
elem = opts.elem;
var xm = xmSelect.render({
el: elem,
radio: true, //单选
toolbar: {show: true}, //开启工具栏
data: []
})
new HttpRequest(url, method, function (obj) {
//转换成xmSelect格式数据
for (var i = 0; i < obj.data.length; i++) {
obj.data[i].name = obj.data[i].dictName;
obj.data[i].value = obj.data[i].dictCode;
}
xm.update({
data: obj.data,
autoRow: true,
});
}, function (data) {
}).set("dictTypeCode", code).start();
return new dict();
};
exports('dict', new dict());
});

@ -0,0 +1,8 @@
<div id="demo1" class="xm-select-demo"></div>
dict.render({
elem: '#demo2', //控件
code: '' //字典dictTypeCode
});
Loading…
Cancel
Save