diff --git a/OpenAuth.Mvc/Views/Categories/Index.cshtml b/OpenAuth.Mvc/Views/Categories/Index.cshtml index db670108..0675398d 100644 --- a/OpenAuth.Mvc/Views/Categories/Index.cshtml +++ b/OpenAuth.Mvc/Views/Categories/Index.cshtml @@ -1,15 +1,17 @@ @section header { - - - + + + } +
-
+ +@@ -39,21 +40,21 @@- \ No newline at end of file + \ No newline at end of file diff --git a/OpenAuth.Mvc/wwwroot/userJs/categories.js b/OpenAuth.Mvc/wwwroot/userJs/categories.js index acb79f8c..3832664a 100644 --- a/OpenAuth.Mvc/wwwroot/userJs/categories.js +++ b/OpenAuth.Mvc/wwwroot/userJs/categories.js @@ -1,6 +1,6 @@ layui.config({ base: "/js/" -}).use(['form','vue', 'ztree', 'layer', 'jquery', 'table','droptree','openauth','utils'], function () { +}).use(['form', 'vue', 'ztree', 'layer', 'jquery', 'table', 'droptree', 'openauth', 'utils'], function () { var form = layui.form, layer = layui.layer, $ = layui.jquery; @@ -9,33 +9,41 @@ layui.config({ $("#menus").loadMenus("Category"); + var initVal = { //初始化的值 + Id: '', + Name: '', + TypeName: '', + TypeId: '', + Description: '' + } + //加载表头 $.getJSON('/Categories/All', - { page: 1, limit: 1 }, - function(data) { - var columns = data.columnFields.filter(u => u.IsList ===true).map(function (e) { + {page: 1, limit: 1}, + function (data) { + var columns = data.columnFields.filter(u => u.IsList === true).map(function (e) { return { field: e.ColumnName, title: e.Comment }; }); - columns.unshift({ - type: 'checkbox', - fixed: 'left' - }); - table.render({ - elem: '#mainList', - page: true, - url: '/Categories/All', - cols: [columns] - , response: { - statusCode: 200 //规定成功的状态码,默认:0 - } - }); - }); - + columns.unshift({ + type: 'checkbox', + fixed: 'left' + }); + table.render({ + elem: '#mainList', + page: true, + url: '/Categories/All', + cols: [columns] + , response: { + statusCode: 200 //规定成功的状态码,默认:0 + } + }); + }); + //主列表加载,可反复调用进行刷新 - var config= {}; //table的参数,如搜索key,点击tree的id + var config = {}; //table的参数,如搜索key,点击tree的id var mainList = function (options) { if (options != undefined) { $.extend(config, options); @@ -45,49 +53,26 @@ layui.config({ where: config , response: { statusCode: 200 //规定成功的状态码,默认:0 - } + } }); } //添加(编辑)对话框 - var editDlg = function() { - var vm; - var update = false; //是否为更新 - var show = function (data) { + var editDlg = function () { + var show = function (update, data) { var title = update ? "编辑信息" : "添加"; layer.open({ title: title, area: ["500px", "400px"], type: 1, content: $('#divEdit'), - success: function() { - if(vm == undefined){ - vm = new Vue({ - el: "#formEdit", - data(){ - return { - tmp:data //使用一个tmp封装一下,后面可以直接用vm.tmp赋值 - } - }, - watch:{ - tmp(val){ - this.$nextTick(function () { - form.render(); //刷新select等 - }) - } - }, - mounted(){ - form.render(); - var _this = this; - layui.droptree("/Categories/AllTypes", "#TypeName", "#TypeId", false,function (ids, names) { - _this.tmp.TypeName = ids; - _this.tmp.TypeId = names; - }); - } - }); - }else{ - vm.tmp = Object.assign({}, vm.tmp,data) - } + success: function () { + layui.droptree("/Categories/AllTypes", "#TypeName", "#TypeId", false); + if (data == undefined) { + form.val("formEdit", initVal); + } else { + form.val("formEdit", data); + } }, end: mainList }); @@ -97,10 +82,10 @@ layui.config({ } //提交数据 form.on('submit(formSubmit)', - function(data) { + function (data) { $.post(url, data.field, - function(data) { + function (data) { layer.msg(data.Message); }, "json"); @@ -109,24 +94,20 @@ layui.config({ } return { add: function() { //弹出添加 - update = false; - show({ - Id: '' - }); + show(false); }, update: function(data) { //弹出编辑框 - update = true; - show(data); + show(true,data); } }; }(); - + //监听表格内部按钮 table.on('tool(list)', function (obj) { var data = obj.data; if (obj.event === 'detail') { //查看 layer.msg('ID:' + data.Id + ' 的查看操作'); - } + } }); @@ -136,26 +117,28 @@ layui.config({ var checkStatus = table.checkStatus('mainList') , data = checkStatus.data; openauth.del("/Categories/Delete", - data.map(function (e) { return e.Id; }), + data.map(function (e) { + return e.Id; + }), mainList); } , btnAdd: function () { //添加 editDlg.add(); } - , btnEdit: function () { //编辑 - var checkStatus = table.checkStatus('mainList') - , data = checkStatus.data; - if (data.length != 1) { - layer.msg("请选择编辑的行,且同时只能编辑一行"); - return; - } - editDlg.update(data[0]); - } + , btnEdit: function () { //编辑 + var checkStatus = table.checkStatus('mainList') + , data = checkStatus.data; + if (data.length != 1) { + layer.msg("请选择编辑的行,且同时只能编辑一行"); + return; + } + editDlg.update(data[0]); + } , search: function () { //搜索 - mainList({ key: $('#key').val() }); + mainList({key: $('#key').val()}); } - , btnRefresh: function() { + , btnRefresh: function () { mainList(); } }; diff --git a/OpenAuth.Mvc/wwwroot/userJs/orgs.js b/OpenAuth.Mvc/wwwroot/userJs/orgs.js index 34e4919f..459e3252 100644 --- a/OpenAuth.Mvc/wwwroot/userJs/orgs.js +++ b/OpenAuth.Mvc/wwwroot/userJs/orgs.js @@ -8,6 +8,14 @@ var openauth = layui.openauth; $("#menus").loadMenus("Org"); + + var initVal = { //初始化的值 + Id: '', + Name: '', + SortNo: '', + ParentName: '', + ParentId: '' + } //主列表加载,可反复调用进行刷新 var config= {}; //table的参数,如搜索key,点击tree的id @@ -66,9 +74,7 @@ //添加(编辑)对话框 var editDlg = function() { - var vm; - var update = false; //是否为更新 - var show = function (data) { + var show = function (update, data) { var title = update ? "编辑信息" : "添加"; layer.open({ title: title, @@ -76,34 +82,12 @@ type: 1, content: $('#divEdit'), success: function() { - if(vm == undefined){ - vm = new Vue({ - el: "#formEdit", - data(){ - return { - tmp:data //使用一个tmp封装一下,后面可以直接用vm.tmp赋值 - } - }, - watch:{ - tmp(val){ - this.$nextTick(function () { - form.render(); //刷新select等 - }) - } - }, - mounted(){ - form.render(); - var _this = this; - layui.droptree("/UserSession/GetOrgs", "#ParentName", "#ParentId", false,function (ids, names) { - _this.tmp.ParentId = ids; - _this.tmp.ParentName = names; - }); - - } - }); + layui.droptree("/UserSession/GetOrgs", "#ParentName", "#ParentId", false); + if (data == undefined) { + form.val("formEdit", initVal); } else { - vm.tmp = Object.assign({}, vm.tmp,data) - } + form.val("formEdit", data); + } }, end: mainList }); @@ -128,15 +112,10 @@ } return { add: function() { //弹出添加 - update = false; - show({ - Id: '', - SortNo:1 - }); + show(false); }, update: function(data) { //弹出编辑框 - update = true; - show(data); + show(true,data); } }; }();