123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- $(document).ready(function () {
- initRoleTable();
- initTree();
- });
- var roleTable;
- var size;
- var number;
- function initRoleTable() {
- var queryUrl = '/Admin/GetRoles';
- roleTable = $("#role_table").bootstrapTable({
- url: queryUrl,
- columns: [
- { field: "id", title: "ID", visible: false },
- { field: "name", title: "角色名称" },
- { field: "createTime", title: "创建时间" },
- {
- title: '操作',
- field: "id",
- formatter: operation,
- width: 300
- }
- ],
- pagination: true,
- pageNumber: 1,
- pageSize: size,
- pageList: [10, 25, 50, 100],
- smartDisplay: false,
- sidePagination: "server",
- queryParams: function (params) {
- var temp = {
- pageNumber: (params.offset / params.limit) + 1,
- pageSize: params.limit,
- keyword: $("#keyword").val()
- };
- number = temp.pageNumber;
- return temp;
- }
- });
- }
- function operation(value, row, index) {
- var htm =
- "<a class='label' onclick='modelPermissions(\"" + value + "\")'> <i class='fa fa-bookmark-o'> 设置权限</i></a >" +
- "<a class='label' onclick='modelUpdateRole(\"" + value + "\")'> <i class='fa fa-edit'> 编辑</i></a >" +
- "<a class='label' onclick='deleteRole(\"" + value + "\")'> <i class='fa fa-trash-o'> 删除</i></a >";
- return htm;
- }
- function modelCreateRole() {
- $("#Id").val("");
- $("#modal_role_add").modal("show");
- }
- function saveRole() {
- var id = $("#Id").val();
- var url;
- if (id === null || id === "") {
- url = "/Admin/CreateRole";
- } else {
- url = "/Admin/UpdateRole/" + id;
- }
- $.ajax({
- url: url,
- method: "POST",
- headers: { "Content-Type": "application/json" },
- async: true,
- data: JSON.stringify({
- "name": $("#Name").val()
- }),
- success: function (result) {
- if (result.code === 0) {
- $("#modal_role_add").modal("hide");
- if (id === null || id === "") {
- refreshRoleTable();
- } else {
- selectPageRoleTable();
- }
- } else if (result.code === 1) {
- alert(result.message);
- }
- }
- });
- }
- function modelUpdateRole(id) {
- $("#Id").val(id);
- $.ajax({
- url: "/Admin/Role/" + id,
- method: "GET",
- headers: { "Content-Type": "application/json" },
- async: true,
- success: function (result) {
- if (result.code === 0) {
- $("#Name").val(result.data.name);
- } else if (result.code === 1) {
- alert(result.message);
- }
- }
- });
- $("#modal_role_add").modal("show");
- }
- function deleteRole(id) {
- $.ajax({
- url: "/Admin/DeleteRole/" + id,
- method: "POST",
- headers: { "Content-Type": "application/json" },
- async: true,
- success: function (result) {
- if (result.code === 0) {
- if (id === null || id === "") {
- refreshRoleTable();
- } else {
- selectPageRoleTable();
- }
- } else if (result.code === 1) {
- alert(result.message);
- }
- }
- });
- }
- function refreshRoleTable() {
- roleTable.bootstrapTable("refreshOptions", { pageNubmer: 1 });
- }
- function selectPageRoleTable() {
- roleTable.bootstrapTable("selectPage", number);
- }
- function modelPermissions(id) {
- $("#Id").val(id);
- $.ajax({
- url: "/Admin/Role/" + id,
- method: "GET",
- headers: { "Content-Type": "application/json" },
- async: true,
- success: function (result) {
- if (result.code === 0) {
- $("#Name2").val(result.data.name);
- } else if (result.code === 1) {
- alert(result.message);
- }
- }
- });
- $.ajax({
- url: "/Admin/Permissions/" + id,
- method: "POST",
- headers: { "Content-Type": "application/json" },
- async: true,
- success: function (result) {
- zTreeObj.checkAllNodes(false);
- for (var i = 0; i < result.length; i++) {
- var node = zTreeObj.getNodeByParam("id", result[i].id);
- zTreeObj.checkNode(node, true, true);
- }
- }
- });
- $("#modal_permissions").modal("show");
- }
- var zTreeObj;
- var setting = {
- check: {
- enable: true
- },
- data: {
- simpleData: {
- enable: true
- }
- }
- };
- //var zNodes = [
- // { id: "1", pId: "0", name: "数据一览" },
- // { id: "2", pId: "0", name: "计划监控" },
- // { id: "3", pId: "0", name: "产线一览" },
- // { id: "4", pId: "0", name: "产线详情" },
- // { id: "5", pId: "0", name: "数据报表" },
- // { id: "6", pId: "0", name: "Cim监控" },
- // { id: "7", pId: "0", name: "配置管理", open: true },
- // { id: "701", pId: "7", name: "机种管理" },
- // { id: "6", pId: "0", name: "系统管理", open: true },
- // { id: "601", pId: "6", name: "用户管理" },
- // { id: "602", pId: "6", name: "角色管理" },
- // { id: "7", pId: "0", name: "故障统计" },
- // { id: "8", pId: "0", name: "能耗统计" },
- // { id: "9", pId: "0", name: "运维管理" }
- //];
- var zNodes = [];
- function initTree() {
- $.ajax({
- url: "/Admin/Menu",
- method: "GET",
- headers: { "Content-Type": "application/json" },
- async: false,
- success: function (result) {
- zNodes = result;
- }
- });
- zTreeObj = $.fn.zTree.init($("#permissions"), setting, zNodes);
- }
- class Menu {
- constructor(id, name) {
- this.id = id;
- this.name = name;
- }
- }
- function savePermissions() {
- var id = $("#Id").val();
- var nodes = zTreeObj.getCheckedNodes(true);
- var dto = new Array();
- for (var i = 0; i < nodes.length; i++) {
- var d = new Menu(nodes[i].id, nodes[i].name);
- dto.push(d);
- }
- $.ajax({
- url: "/Admin/SetPermissions/" + id,
- method: "POST",
- headers: { "Content-Type": "application/json" },
- async: true,
- data: JSON.stringify(dto),
- success: function (result) {
- if (result.code === 0) {
- $("#modal_permissions").modal("hide");
- } else if (result.code === 1) {
- alert(result.message);
- }
- }
- });
- }
|