模板中图片按钮怎么设置重置功能 加入onclick="this.form.reset();"为什么不行

本文介绍如何在HTML表单中使用图片作为取消按钮,并通过JavaScript阻止默认提交行为的方法。原本尝试直接使用form的reset方法未能生效,最终通过添加return false解决该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用模板中的图片按钮“取消”,加入了

<input type="image" name="Submit2" src="images/zblogin_11.png" width="84" height="25" onClick="this.form.reset();""></td>

从上面可以看出来type是image,加入了onClick="this.form.reset();方法,却不好使,把上面的代码换成下面的就可以了

<input type="image" name="Submit2" src="images/zblogin_11.png" width="84" height="25" onClick="this.form.reset(); <span style="color:#FF0000;">return false;</span>""></td>
加入return false就是让让“提交”动作失效即可。


在此感谢无所不知的度娘。

原文:http://zhidao.baidu.com/link?url=Dbu2pYYIZBKmFmMPsVbx_hczASZ6p-HcQ1jDHcopZM_OdKEwddPYTUp3b8adfTe4--5f-pCCkjohmHxcZZJTYwolUd6drNRnyR5qa7-tWqe

<template> <div> <title>{{$route.name}}</title> <h1>{{$route.name}}</h1> <aui-form id="editForm"> <div class="first-field" :class="isShowMore?'showMore':'hideMore'"> <aui-form-item label="版本号" label-width="110px"> <aui-dropdown size="small" v-model="searchForm.planId" :op="planIdOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="厂区" label-width="110px"> <aui-dropdown size="small" v-model="searchForm.locationCodeStr" :op="siteCodeOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="部门" label-width="110px"> <aui-dropdown size="small" ref="deptCodeRef" v-model="searchForm.deptNameStr" :op="deptOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="工序" label-width="110px"> <aui-dropdown size="small" v-model="searchForm.workSerctionStr" :op="workSerctionOp"></aui-dropdown> </aui-form-item> <aui-form-item label="产品线" label-width="110px"> <aui-dropdown size="small" ref="prodLineCnNameRef" v-model="searchForm.prodLineCnNameStr" :op="prodLineOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="产品族" label-width="110px"> <aui-dropdown size="small" ref="prodFamilyEnNameRef" v-model="searchForm.prodFamilyEnNameStr" :op="prodFamilyOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="产品型号" label-width="110px"> <aui-dropdown size="small" ref="prodModelCodeRef" v-model="searchForm.prodModelCodeStr" :op="prodModelCodeOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item label="物料编码" label-width="110px"> <aui-input size="small" ref="itemCodeRef" v-model="searchForm.itemCodeStr" placeholder="连续首字母或者字符可模糊匹配"></aui-input> </aui-form-item> <aui-form-item label="类型" label-width="110px"> <aui-dropdown size="small" v-model="searchForm.dataTypeStr" :op="dataTypeOp" place-holder="请选择"></aui-dropdown> </aui-form-item> <aui-form-item class="first-field-btn" label-width="0px" style="width: 265px"> <i v-show="isTriangleIconShow" class="hae-icon" :class="isShowMore?'icon-down':'icon-left-o'" @click="isShowMore = !isShowMore "></i> <aui-button type="primary" size="mini" round @click="findClick">查询</aui-button> <aui-button type="primary" size="mini" round @click="reset" style="margin-right: 8px">重置</aui-button> <FormTempBtn style="width:100px;" :form-code="formId" :formData="searchForm" @templateChanged="setFormData"></FormTempBtn> </aui-form-item> </div> </aui-form> <div class="table-auto"> <aui-grid height="100%" auto-resize ref="grid" :auto-load="false" resizable :row-class-name="rowClassName" :pager="pagerConfig" border :span-method="colspanMethod" :fetch-data="fetchData"> <template #toolbar> <aui-grid-toolbar id="scheduleSupplyDemandGridId" :setting="{ showIndex: true, sortable: Sortable, }" ref="auiToolbar" @remote-setting="remoteSetting" @save-setting="saveSetting"> <template #buttons> <div style="width: 800px; display: inline-block"> <aui-button size="mini" @click="exportData">导出</aui-button> <aui-button size="mini" @click="showBaseLoggerInfo">版本日志</aui-button> </div> </template> </aui-grid-toolbar> </template> <aui-grid-column fixed="left" title="版本" field="planId" min-width="100" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="厂区" field="locationName" min-width="100" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="部门" field="deptName" min-width="120" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="产品线" field="prodLineCnName" min-width="80" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="产品族" field="prodFamilyEnName" min-width="80" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="产品型号" field="prodModelCode" min-width="80" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="工序" field="workSerction" min-width="80" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="物料编码" field="itemCode" min-width="90" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="类型" field="dataType" min-width="80" show-overflow header-align="center" align="center"></aui-grid-column> <aui-grid-column fixed="left" title="库存" field="invQty" min-width="80" show-overflow header-align="center" align="center"> <template #default="{ row }"> <div style="color: #189ff0 !important;cursor: pointer;text-decoration: underline;" @click="operateRow(row, 'invQty')">{{ row.invQty }}</div> </template> </aui-grid-column> <aui-grid-column fixed="left" title="历史" field="hisQty" min-width="100" show-overflow header-align="center" align="center"> <template #default="{ row }"> <div :class="{ 'row-link_click': ['预计供应', '过站供应', '排产需求'].includes(row.dataType), 'row-link-red': String(row.hisQty) && row.hisQty < 0 }" @click="operateRow(row, 'hisQty')">{{ row.hisQty }}</div> </template> </aui-grid-column> <aui-grid-column v-for="(item, i) in dateItem" :key="i" :field="item.field" :title="item.title" :renderer="renderFunction" min-width="50" align="center"> </aui-grid-column> </aui-grid> </div> <StockDialog v-if="showStock" :rowData="rowData" @changeDialog="changeDialog"></StockDialog> <InProcessWorkOrderSchedule v-if="showInProcess" :rowData="rowData" @changeDialog="changeDialog" :dateItem="dateItem"></InProcessWorkOrderSchedule> <WorkOrderScheduleHistory v-if="showHistory" :rowData="rowData" @changeDialog="changeDialog" :dateItem="dateItem"></WorkOrderScheduleHistory> <aui-dialog-box title="版本日志" class="history-Info" v-model="isShowBaseLoggerInfo" width="90%" top="8%" :dragable="true" :modal-closable="false"> <base-logger-info v-bind:apiUrl="getLoggerInfoUrl" v-if="isShowBaseLoggerInfo"></base-logger-info> </aui-dialog-box> </div> </template> <script> import { Form, FormItem, Dropdown, Hae, $, DialogBox } from '@aurora/ui3' import { Grid, GridColumn, Modal, Pager, Button, GridToolbar } from '@aurora/vue3' import { FormTempBtn } from '@mxdesign/ui' import Sortable from 'sortablejs' import { remoteSettingFn, saveSettingFn, getCustomConfigsFn } from '@/utils/personSettings' import StockDialog from '@/components/supplydemandmgt/StockDialog' import InProcessWorkOrderSchedule from '@/components/supplydemandmgt/InProcessWorkOrderSchedule' import WorkOrderScheduleHistory from '@/components/supplydemandmgt/WorkOrderScheduleHistory' import BaseLoggerInfo from '../basedata/BaseLoggerInfo.vue' export default { components: { AuiDialogBox: DialogBox, AuiButton: Button, AuiForm: Form, AuiFormItem: FormItem, AuiDropdown: Dropdown, AuiGrid: Grid, AuiGridColumn: GridColumn, AuiGridToolbar: GridToolbar, FormTempBtn, StockDialog, InProcessWorkOrderSchedule, WorkOrderScheduleHistory, BaseLoggerInfo }, computed: { tableData() { return this.$refs.grid && this.$refs.grid.getTableData() ? this.$refs.grid.getTableData().tableData : [] } }, data() { return { Sortable, isShowBaseLoggerInfo: false, getLoggerInfoUrl: 'services/supplyRequireItemHeadService/getSupplyRequireLogList/page/{{pageSize}}/{{curPage}}', formId: 'scheduleSupplyDemandId', toolBoxShow: false, isShowMore: true, isTriangleIconShow: true, searchForm: { planId: '', // 版本号 locationCodeStr: '', // 厂区 deptNameStr: '', // 部门 prodLineCnNameStr: '', // 产品线 prodFamilyEnNameStr: '', // 产品族 prodModelCodeStr: '', // 产品型号 workSerctionStr: '', // 工序 itemCodeStr: '', // 编码 dataTypeStr: '' // 类型 }, // 版本号 planIdOp: { multi: false, showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, id: 'planId', validation: { required: true }, textField: 'planId', valueField: 'planId', placeHolder: '-----请选择-----', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getAllPlanIdList' } } }, // 厂区 siteCodeOp: { multi: true, id: 'locationCodeId', showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, textField: 'locationName', valueField: 'locationCode', placeHolder: '-----请选择-----', emptyDataMsg: '-----没有数据-----', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getAllLocationInfo' } } }, // 部门 deptOp: { multi: true, // 是否多选 id: 'deptCodeId', showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, textField: 'deptName', valueField: 'deptName', placeHolder: '-----请选择-----', emptyDataMsg: '-----请选择厂区-----', dataset: { source: { type: 'POST', url: 'services/apsSupplyRequireService/getDeptInfo' } }, cascade: [ { trigger: '#locationCodeId', allowEmpty: false, // 是否允许空值参加级联 name: 'locationCodeStr' } ] }, // 工序 workSerctionOp: { id: 'workSerctionId', multi: true, showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, placeHolder: '-----请选择-----', textField: 'valueInfo', valueField: 'valueInfo', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getAllWorkSerction' } } }, // 产品线 prodLineOp: { multi: true, id: 'prodLineId', showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, textField: 'prodLineCnName', valueField: 'prodLineCnName', placeHolder: '-----请选择-----', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getProdLineList' } } }, // 产品族(系列) prodFamilyOp: { multi: true, id: 'prodFamilyId', showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, textField: 'prodSeriesEnName', valueField: 'prodSeriesEnName', placeHolder: '-----请选择-----', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getProdSeriesList' } }, cascade: [ { trigger: '#prodLineId', allowEmpty: true, // 是否允许空值参加级联 name: 'prodLineCnNameStr' } ], emptyDataMsg: '-----请选择产品线-----' }, // 产品型号 prodModelCodeOp: { multi: true, id: 'prodModelId', showClearBtn: true, autoSelect: false, alwaysLoad: true, editable: true, textField: 'prodModelCode', valueField: 'prodModelCode', placeHolder: '-----请选择-----', dataset: { source: { type: 'post', url: 'services/apsSupplyRequireService/getAllProdModelList' } }, cascade: [ { trigger: '#prodFamilyId', allowEmpty: false, name: 'prodSeriesEnNameStr' } ], emptyDataMsg: '-----请选择产品族-----' }, // 类型 dataTypeOp: { multi: true, id: 'dataTypeId', showClearBtn: true, autoSelect: false, editable: true, textField: 'label', valueField: 'value', placeHolder: '-----请选择-----', dataset: { value: [ { value: '排产', label: '排产' }, { value: '预计供应', label: '预计供应' }, { value: '过站供应', label: '过站供应' }, { value: '排产需求', label: '排产需求' }, { value: '供需匹配', label: '供需匹配' } ] } }, pageFlag: false, pagerConfig: { component: Pager, attrs: { currentPage: 1, pageSize: 15, pageSizes: [15, 30, 50, 100], total: 0, layout: 'total, sizes, prev, pager, next, jumper' } }, dateItem: [], fetchData: { api: this.getData }, clickSearchForm: {}, rowData: {}, showStock: false, showInProcess: false, showHistory: false, settingType: 'scheduleSupplyDemand', setTableColumn: [] } }, methods: { showBaseLoggerInfo() { this.isShowBaseLoggerInfo = true }, // 导出 exportData() { let formData = this.searchForm Hae.ajax({ url: 'services/exportFileUtilService/exportApsSupplyRequire', data: formData, type: 'post', success: () => { Hae.confirm('导出任务已开始,你可以进入[我的导入导出>导出查询]中查看任务状态并下载导出文件!', (bool) => { if (bool) { window.open('#/ListExport') } }) } }) }, // 行合并 colspanMethod({ row, column, rowIndex, columnIndex }) { let fields = ['mergerKey', 'invQty'] // 获取当前行的 mergerKey const currentGroupKey = row.mergerKey // 获取当前列的 prop const columnProp = column.property // 计算相同 mergerKey 的行范围 const groupRows = this.tableData.filter((item) => item.mergerKey === currentGroupKey && currentGroupKey) const firstGroupRowIndex = this.tableData.findIndex( (item) => item.mergerKey === currentGroupKey && currentGroupKey ) const lastGroupRowIndex = firstGroupRowIndex + groupRows.length - 1 // 对于 fields 列,合并相同 mergerKey 的所有行 if (fields.includes(columnProp)) { if (rowIndex === firstGroupRowIndex) { return { rowspan: groupRows.length, colspan: 1 } } else { return { rowspan: 0, colspan: 0 } } } }, // 行渲染 renderFunction(h, { row, column }) { if (row.dataType === '排产需求'&& Number(row[column.property]) < 0) { return <span style={{ color: '#000', fontSize: '12px' }}>{row[column.property]}</span> } if (String(row[column.property]) && Number(row[column.property]) < 0) { return <span style={{ color: '#fe281f', fontSize: '12px' }}>{row[column.property]}</span> } else { return <span style={{ color: '#000', fontSize: '12px' }}>{row[column.property]}</span> } }, rowClassName({ seq, row, rowIndex, $rowIndex }) { if (row.dataType === '排产') { return 'row__word--remarked' } else { return '' } }, setFormData(data) { let tempArr = Object.keys(data) this.resData = data if (tempArr.length === 0) { return } this.searchForm.planId = data.planId // 版本号 this.searchForm.locationCodeStr = data.locationCodeStr // 厂区 this.searchForm.prodLineCnNameStr = data.prodLineCnNameStr // 产品线 this.searchForm.workSerctionStr = data.workSerctionStr // 工序 this.searchForm.dataTypeStr = data.dataTypeStr // 类型 // 级联关系接口先后执行 setTimeout(() => { this.$refs.deptCodeRef.widget.setValueByField(data.deptNameStr, 'deptName') // 注意: 第二个参数是下拉的value值,不是v-model的值 }, 500) setTimeout(() => { this.$refs.prodFamilyEnNameRef.widget.setValueByField(data.prodFamilyEnNameStr, 'prodSeriesEnName') }, 800) setTimeout(() => { this.$refs.prodModelCodeRef.widget.setValueByField(data.prodModelCodeStr, 'prodModelCode') }, 1500) setTimeout(() => { this.$refs.itemCodeRef.widget.setValueByField(data.itemCodeStr, 'prodItemCode') }, 2000) }, operateRow(row, flag) { this.rowData = row this.rowData.dialogFlag = flag if (flag === 'invQty') { this.showStock = true } else { if (['排产需求'].includes(row.dataType)) { this.showHistory = true } if (['预计供应', '过站供应'].includes(row.dataType)) { this.showInProcess = true } } }, handleProductionClick(row,flag){ this.rowData = row this.rowData.dialogFlag = flag if(['排产需求'].includes(row.dataType)){ this.showHistory=true } }, changeDialog() { this.rowData = {} this.showStock = false this.showHistory = false this.showInProcess = false }, reset() { // 清空选择 this.searchForm = { planId: '', // 版本号 locationCodeStr: '', // 厂区 deptNameStr: '', // 部门 prodLineCnNameStr: '', // 产品线 prodFamilyEnNameStr: '', // 产品族 prodModelCodeStr: '', // 产品型号 workSerctionStr: '', // 工序 itemCodeStr: '', // 编码 dataTypeStr: '' // 类型 } this.clickSearchForm = JSON.parse(JSON.stringify(this.searchForm)) }, // 动态日期列 columnDate() { this.dateItem = [] let params = { ...this.searchForm } this.$service.network.post('services/apsSupplyRequireService/getHeadBucketList', params).then(({ data }) => { this.pageFlag = false if (data && data.length) { data.forEach((element) => { // 将完整日期转换为月日格式 MM/DD const dateParts = element.split('-') const monthDay = dateParts.length >= 3 ? `${dateParts[1]}/${dateParts[2]}` : element this.dateItem.push({ title: monthDay, field: element }) }) } }) }, findClick() { Hae.validForm($('#editForm'), (valid) => { if (valid) { this.pageFlag = true this.getCustomConfigs() this.clickSearchForm = JSON.parse(JSON.stringify(this.searchForm)) setTimeout(() => { this.$refs.grid.handleFetch() }, 500) } }) }, // 查询 getData({ page }) { let { pageSize } = page if (this.pageFlag) { page.currentPage = 1 } let curPage = page.currentPage return new Promise((resolve, reject) => { let params = { ...this.clickSearchForm } this.$service.network .post(`services/apsSupplyRequireService/getApsSupplyRequireList/page/${pageSize}/${curPage}`, params) .then(({ data }) => { this.pageFlag = false this.isShowMore = false this.columnDate() let totalRows = data.pageVO && data.pageVO.totalRows ? data.pageVO.totalRows : 0 let result = data.result && data.result.length ? data.result : [] resolve({ result, page: { total: totalRows } }) }) }) }, getCustomConfigs() { let config = { settingType: this.settingType, grid: 'grid', auiToolbar: 'auiToolbar', setTableColumn: 'setTableColumn', dragSort: true } getCustomConfigsFn.call(this, config) }, remoteSetting(settings) { remoteSettingFn.call(this, settings, 'grid') }, saveSetting() { let customConfigs = arguments[0].columns let config = { settingType: this.settingType, customConfigs } saveSettingFn.call(this, config) } }, mounted() { let that = this // 判断是否有更多条件显示隐藏小三角 let editFormHeight = $('.first-field').outerHeight() that.isTriangleIconShow = !(editFormHeight < 38) that.isShowMore = false this.getCustomConfigs() } } </script> <style scoped src="./../unit/css/newModelPublic.css"></style> <style scoped> .first-field { padding-right: 300px !important; } :deep(.table-auto .aui-grid .aui-grid-cell) { width: 100% !important; font-size: 12px; } .table-auto { height: calc(100vh - 140px) !important; } :deep(.table-auto .aui-grid__body-wrapper) { height: calc(100vh - 280px) !important; } :deep(.aui-grid__body-wrapper::-webkit-scrollbar) { height: 12px !important; width: 12px !important; } :deep(.aui-grid__body .aui-grid-body__column .aui-grid-cell .row-link) { color: #189ff0 !important; cursor: pointer; text-decoration: underline; } :deep(.aui-grid-toolbar) { padding: 5px 0; } :deep(.aui-grid-toolbar .aui-grid-custom__wrapper) { height: 24px !important; width: 24px !important; } :deep(.aui-grid__body .aui-grid-body__column .aui-grid-cell .row-link_click) { color: #189ff0 !important; cursor: pointer; text-decoration: underline; } :deep(.aui-grid__body .aui-grid-body__column .aui-grid-cell .row-link-red) { color: #fe281f !important; } :deep(.aui-grid.fixed__sticky .row__word--remarked) { --body-background-color: #ebf1de !important; } :deep(.row__word--remarked) { background-color: #ebf1de !important; } :deep(.aui-grid .aui-pager) { padding-top: 6px !important; } </style> <style> /* 隐藏aui3个性化重置按钮 */ .aui-grid-modal__box .aui-grid-custom .aui-grid-custom__footer .aui-button:nth-child(2) { display: none !important; } </style> 中在dataItem动态生成的日期列中对应的数值类型是排产需求的点击数值展示WorkOrderScheduleHistory页面,
最新发布
08-15
using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; using System.Web.Mvc; using WebApplication1.Models; using WebApplication1.Scripts; namespace WebApplication1.Controllers { [LoginActionFitter] public class OrgManagemController : Controller { AoutEntities1 db = new AoutEntities1(); ReturnJsonData jsonData = new ReturnJsonData(); Models.ReturnListJsonData orgTreeList = new Models.ReturnListJsonData(); // GET: OrgManagem public ActionResult Index() { return View(); } #region 查询 /// <summary> /// 模糊查询 /// </summary> /// <param name="page"></param> /// <param name="limit"></param> /// <param name="orgname"></param> /// <returns></returns> public ActionResult GetList(int page, int limit, string orgname) { //返回树形表格 List<object> retultlist = new List<object>(); //第一步 查找所有的一级菜单 var list = db.OrganizationStructure.Where(a => a.ParentId == Guid.Empty).ToList(); if (!string.IsNullOrEmpty(orgname)) { list = db.OrganizationStructure.Where(a => a.OrgName.Contains(orgname)).ToList(); foreach (var itme in list) { ReturnTreeListData obj = new ReturnTreeListData(); obj.ID = itme.ID; obj.parentId = itme.ParentId; obj.name = itme.OrgName; obj.OrgCode = itme.OrgCode; obj.Leve = itme.Leve; obj.CreateDate = itme.CreateDate; obj.ModifyDate = itme.ModifyDate; //验证是否还有有子集 obj.isParent = false; obj.children = null; retultlist.Add(obj); } } else { list = db.OrganizationStructure.Where(a => a.ParentId == Guid.Empty).ToList(); //循环 foreach (var itme in list) { ReturnTreeListData obj = new ReturnTreeListData(); obj.ID = itme.ID; obj.parentId = itme.ParentId; obj.name = itme.OrgName; obj.OrgCode = itme.OrgCode; obj.Leve = itme.Leve; obj.CreateDate = itme.CreateDate; obj.ModifyDate = itme.ModifyDate; //验证是否还有有子集 obj.isParent = db.OrganizationStructure.Where(a => a.ParentId == itme.ID).ToList().Count > 0 ? true : false; if (obj.isParent == true) { //查找所以子集 obj.children = BuildTree(list, itme.ID); } retultlist.Add(obj); } } orgTreeList.code = 0; orgTreeList.count = list.Count; orgTreeList.data = retultlist; return Json(orgTreeList, JsonRequestBehavior.AllowGet); } #endregion public ActionResult GetEditData(Guid nodeId) { var current = db.OrganizationStructure.Find(nodeId); if (current == null) return Json(new { success = false }); // 总公司的ParentId为null或自身(假设总公司ParentId=0或null) var isRoot = current.ParentId == null || current.ParentId == Guid.Empty; var parent = isRoot ? current : db.OrganizationStructure.Find(current.ParentId); return Json(new { parentName = parent.OrgName, parentCode = parent.OrgCode, level = current.Leve, orgName = current.OrgName, orgCode = current.OrgCode, ID = current.ID, parentID = current.ParentId, }, JsonRequestBehavior.AllowGet); } #region 递归调用 /// <summary> /// 递归调用 /// </summary> /// <param name="list"></param> /// <param name="ID"></param> /// <returns></returns> private List<object> BuildTree(List<OrganizationStructure> list, Guid ID) { List<object> Treelist = new List<object>(); List<OrganizationStructure> childList = db.OrganizationStructure.Where(a => a.ParentId == ID).ToList(); //循环 foreach (var itme in childList) { ReturnTreeListData obj = new ReturnTreeListData(); obj.ID = itme.ID; obj.parentId = itme.ParentId; obj.name = itme.OrgName; obj.OrgCode = itme.OrgCode; obj.Leve = itme.Leve; obj.CreateDate = itme.CreateDate; obj.ModifyDate = itme.ModifyDate; obj.isParent = db.OrganizationStructure.Where(a => a.ParentId == itme.ID).ToList().Count > 0 ? true : false; obj.children = BuildTree(childList, itme.ID); Treelist.Add(obj); } return Treelist; } #endregion #region 新增组织机构 /// <summary> /// 新增,修改 /// </summary> /// <returns></returns> public ActionResult Add(OrganizationStructure org) { org.ID = Guid.NewGuid(); org.Leve = 0; org.ParentId = Guid.Empty; org.CreateDate = DateTime.Now; org.ModifyDate = DateTime.Now; db.OrganizationStructure.Add(org); var result = db.SaveChanges(); if (result > 0) { jsonData.code = 0; jsonData.msg = "新增组织机构成功"; } else { jsonData.code = 1; jsonData.msg = "新增失败,请联系管理员"; } return Json(jsonData, JsonRequestBehavior.AllowGet); } #endregion #region 删除 /// <summary> /// 删除操作 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult DelInfo(Guid? id) { if (id == null) { jsonData.code = 1; jsonData.msg = "删除失败,未找到当行数据"; } else { //删除 var entity = db.OrganizationStructure.Find(id); if (entity == null) { jsonData.code = 1; jsonData.msg = "删除失败,未找到当前行数据"; } else { db.OrganizationStructure.Remove(entity); var result = db.SaveChanges(); if (result > 0) { jsonData.code = 0; jsonData.msg = "删除成功"; } else { jsonData.code = 1; jsonData.msg = "删除失败,请联系管理员"; } } } return Json(jsonData, JsonRequestBehavior.AllowGet); } #endregion #region 新增修改 /// <summary> /// 新增,修改 /// </summary> /// <returns></returns> public ActionResult AddTreeInfo(string neworgname, string neworgcode, OrganizationStructure org, Guid?ID, Guid ParentId) { if (ID == null || ID == Guid.Empty) { // 新增逻辑:parentId为父节点ID(新增时需传递) var newOrg = new OrganizationStructure { ID = Guid.NewGuid(), ParentId = ParentId, OrgName = neworgname, OrgCode = neworgcode, Leve = org.Leve, CreateDate = DateTime.Now, ModifyDate = DateTime.Now }; db.OrganizationStructure.Add(newOrg); } else { // 编辑逻辑:通过ID查找当前行(确保是当前行,而非总公司,依赖ID唯一性) var entity = db.OrganizationStructure.Find(ID); if (entity != null) { entity.OrgName = neworgname; entity.OrgCode = neworgcode; entity.Leve = org.Leve; entity.ModifyDate = DateTime.Now; db.Entry(entity).State = EntityState.Modified; } } var result = db.SaveChanges(); if (result > 0) { jsonData.code = 0; jsonData.msg = "保存成功"; } else { jsonData.code = 1; jsonData.msg = "保存失败,请联系管理员"; } return Json(jsonData, JsonRequestBehavior.AllowGet); } #endregion } } @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Demo</title> <!-- 请勿在项目正式环境中引用该 layui.css 地址 --> <link href="~/Scripts/layui/css/layui.css" rel="stylesheet" /> <script src="~/Scripts/layui/layui.js"></script> <script src="~/Scripts/jquery-3.4.1.js"></script> <style> body { padding: 10px 20px 20px 20px; width: 90% } .editInfo { display: none; } .addeditInfo { display: none; } .addorgfrom { border-radius: 8px; width: 400px; max-width: 100%; padding: 0px 35px 0; margin: auto; position: absolute; top: 60%; left: 55%; margin: -120px 0 0 -230px; } .addform { border-radius: 8px; width: 400px; max-width: 100%; padding: 0px 35px 0; margin: auto; position: absolute; top: 40%; left: 54%; margin: -120px 0 0 -230px; } .layui-form-item { margin-left: -31px; } </style> </head> <body> <fieldset class="layui-elem-field"> <legend> <span class="layui-breadcrumb"> <a href="/Home/Index">首页</a> <a href="/JobManagem/Index">组织机构管理管理</a> </span> </legend> <div class="layui-field-box"> <div class="layui-form-item"> <div class="layui-inline"> <label class="layui-form-label" style="width:90px;">组织机构名称</label> <div class="layui-input-block" style="margin-left:120px"> <input type="text" name="orgname" id="name" autocomplete="off" class="layui-input"> </div> </div> <button type="button" class="layui-btn layui-btn but" style=" margin-bottom: 4px;" id="searchButton" onclick="Search()"><i class="layui-icon layui-icon-search"></i>查询</button> <button type="button" class="layui-btn layui-bg-blue but" style=" margin-bottom: 4px;" onclick="Add()"><i class="layui-icon layui-icon-addition"></i>添加</button> </div> </div> </fieldset> <table class="layui-hide" id="ID-treeTable-demo" lay-filter="test"></table> <script type="text/html" id="TPL-treeTable-demo-tools"> <div class="layui-btn-container"> <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i>新增</a> <a class="layui-btn layui-bg-blue layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a> <a class="layui-btn layui-bg-red layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a> </div> </script> <div class="editInfo"> <form class="layui-form layui-form-pane addorgfrom" action="" lay-filter="demo-val-filter"> <input type="hidden" name="ID" /> <div class="layui-form-item"> <label class="layui-form-label" style="width:130px">组织机构名称</label> <div class="layui-input-block"> <input type="text" name="orgname" autocomplete="off" placeholder="请输入组织机构名称" lay-verify="required" class="layui-input" style="width:87%"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" style="width:130px">组织机构代码</label> <div class="layui-input-block"> <input type="text" name="orgcode" autocomplete="off" placeholder="请输入组织机构代码" lay-verify="required" class="layui-input" style="width:87%"> </div> </div> <div class="layui-form-item" style="text-align:center" id="but"> <div class="layui-input-block" style="margin-left:-53px;padding:10px"> <button type="submit" class="layui-btn" lay-submit lay-filter="demo1" id="add" style="margin:10px">保存</button> <button type="reset" class="layui-btn layui-btn-primary" style="margin-left:30px;">重置</button> </div> </div> </form> </div> @*表格内的新增*@ <div class="addeditInfo"> <form class="layui-form layui-form-pane addform" action="" lay-filter="demo-val-filter"> <input type="hidden" name="ID" /> <input type="hidden" name="ParentId" /> <div class="layui-form-item"> <label class="layui-form-label" style="width:130px">上一级菜单名称</label> <div class="layui-input-block"> <input type="text" name="orgname" autocomplete="off" disabled="disabled" placeholder="请输入组织机构名称" lay-verify="required" class="layui-input" style="width:87%"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" style="width:130px">上一级菜单代码</label> <div class="layui-input-block"> <input type="text" name="orgncode" autocomplete="off" disabled="disabled" placeholder="请输入组织机构名称" lay-verify="required" class="layui-input" style="width:87%"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" style="width:120px">当前级别</label> <div class="layui-input-block" style="margin-left: 121px;width:289px"> <select name="leve" lay-verify="required"> <option value="">请选择级别</option> <option value="0">集团总部</option> <option value="1">分公司</option> <option value="2">部门</option> <option value="3">其他</option> </select> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" style="width:120px">组织机构名称</label> <div class="layui-input-block"> <input type="text" name="neworgname" autocomplete="off" placeholder="请输入组织机构名称" lay-verify="required" class="layui-input" style="width:90%"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" style="width:120px">组织机构代码名称</label> <div class="layui-input-block"> <input type="text" name="neworgcode" autocomplete="off" placeholder="请输入组织机构代码名称" lay-verify="required" class="layui-input" style="width:90%"> </div> </div> <div class="layui-form-item" style="text-align:center" id="but"> <div class="layui-input-block" style="margin-left:-53px;padding:10px"> <button type="submit" class="layui-btn" lay-submit lay-filter="demo2" id="add" style="margin:10px">保存</button> <button type="reset" class="layui-btn layui-btn-primary" style="margin-left:30px;">重置</button> </div> </div> </form> </div> <script> var SearchtreeTable; layui.use(['form', 'table'], function () { var table = layui.table; var treeTable = layui.treeTable; var layer = layui.layer; var form = layui.form; // 渲染 var inst = treeTable.render({ elem: '#ID-treeTable-demo', url: '/OrgManagem/GetList', // 此处为静态模拟数据,实际使用时需换成真实接口 cols: [[ { type: 'checkbox', }, { field: 'ID', title: 'ID', hide: true }, // 隐藏但保留数据 { field: 'ParentId', title: '父ID', hide: true }, // 隐藏但保留数据 { field: 'name', title: '组织机构名称', width: '30%', }, { field: 'OrgCode', title: '组织机构代码', width: '30%', sort: true }, { field: 'Leve', title: '级别', width: '20%', sort: true, templet: function (d) { switch (d.Leve) { case 0: return "集团总部"; break; case 1: return "分公司"; break; case 2: return "部门"; break; default: return "其他"; break; } } }, { title: "操作", width: '16%', align: "center", toolbar: "#TPL-treeTable-demo-tools" } ]], tree: { iconIndex: 1, // 图标显示在第 2 列(对应“组织机构名称”列,索引从 0 开始) isParent: 'isParent', // 绑定后台的 `isParent` 字段(标识是否有子节点) // 删除 async 配置!后台已返回完整 children 数组,无需异步加载 }, page: true }); SearchtreeTable = inst; //编辑,删除 table.on('tool(test)', function (obj) { // 双击 toolDouble var data = obj.data; // 获得当前行数据 // console.log(obj) if (obj.event === 'add') { //新增子集 layer.open({ type: 1, // page 层类型 area: ['550px', '480px'], title: '新增组织机构', shade: 0.6, // 遮罩透明度 shadeClose: false, // 点击遮罩区域,关闭弹层 maxmin: false, // 允许全屏最小化 anim: 0, // 0-6 的动画形式,-1 不开启 content: $(".addeditInfo").html() }); //赋值 form.val('demo-val-filter', { "orgname": data.name, "orgncode": data.OrgCode, "ID": null, "ParentId": data.ID }); } else if (obj.event === 'edit') { //编辑 //修改编辑职位 layer.open({ type: 1, area: ['550px', '480px'], title: '编辑组织机构', shade: 0.6, // 遮罩透明度 shadeClose: false, // 点击遮罩区域,关闭弹层 maxmin: false, // 允许全屏最小化 anim: 0, // 0-6 的动画形式,-1 不开启 content: $('.addeditInfo').html(), success: function () { $.ajax({ url: '/OrgManagem/GetEditData', data: { nodeId: data.ID }, success: function (res) { // 填充数据,处理父节点不存在的情况 form.val('demo-val-filter', { "orgname": res.parentName || data.name, // 父节点不存在时显示自身名称 "orgncode": res.parentCode || data.orgCode, // 父节点不存在时显示自身代码 "leve": res.level, "neworgname": data.name, "neworgcode": data.OrgCode, "ID": res.ID, "ParentId": res.parentID }); } }); } }); } else { layer.confirm('真的删除行 [' + data.name + '] 么', function (index) { obj.del(); // 删除对应行(tr)的DOM结构 layer.close(index); // 向服务端发送删除指令 $.ajax({ url: '/OrgManagem/DelInfo', type: 'post', data: { id: data.ID }, success: function (res) { if (res.code == 0) { layer.msg(res.msg, { icon: 6, time: 1500 }, function () { Search(); }) } else { layer.msg(res.msg, { icon: 5, time: 1500 }) } } }) }); } }); // 提交事件 form.on('submit(demo1)', function (data) { var field = data.field; // 获取表单字段值 // 此处可执行 Ajax 等操作 $.ajax({ url: '/OrgManagem/Add', type: 'post', data: field, success: function (res) { if (res.code == 0) { layer.msg(res.msg, { icon: 6, time: 3000 }, function () { layer.closeAll(); // 关闭所有类型的层 Search(); }); } else { layer.msg(res.msg, { icon: 5, time: 2000 }); } } }) return false; // 阻止默认 form 跳转 }); // 提交事件 form.on('submit(demo2)', function (data) { var field = data.field; // 获取表单字段值 var leve = data.leve; var ParentId = data.ParentId; // 此处可执行 Ajax 等操作 $.ajax({ url: '/OrgManagem/AddTreeInfo', type: 'post', data: field, leve, ParentId, success: function (res) { if (res.code == 0) { layer.msg(res.msg, { icon: 6, time: 3000 }, function () { layer.closeAll(); // 关闭所有类型的层 Search(); }); } else { layer.msg(res.msg, { icon: 5, time: 2000 }); } } }) return false; // 阻止默认 form 跳转 }); }); //重载,模糊查询 function Search() { var nameVal = $('input[name="orgname"]').val().trim(); // 完整重载 - 所有属性属性(options)均可参与到重载中 SearchtreeTable.reload({ where: { // 传递数据异步请求时携带的字段 orgname: nameVal, }, height: 500 // 重设高度 }); } //添加 function Add() { // 在此处输入 layer 的任意代码 layer.open({ type: 1, // page 层类型 area: ['550px', '350px'], title: '新增组织机构', shade: 0.6, // 遮罩透明度 shadeClose: true, // 点击遮罩区域,关闭弹层 maxmin: true, // 允许全屏最小化 anim: 0, // 0-6 的动画形式,-1 不开启 content: $(".editInfo").html() }); } </script> </body> </html>按照这中代码格式和风格写出上面的添加和编辑
07-15
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Index</title> <link href="~/Scripts/layui/css/layui.css" rel="stylesheet" /> <script src="~/Scripts/layui/layui.js"></script> <script src="~/Scripts/jquery-3.4.1.js"></script> <style> body { padding: 10px 20px 20px 20px; width: 90% } .editInfo { display: none; } .addeditInfo { display: none; } .editnewInfo { display: none; } </style> </head> <body> <fieldset class="layui-elem-field"> <legend> <span class="layui-breadcrumb"> <a href="/Home/Index">首页</a> <a href="/JobManagem/Index">菜单管理</a> </span> </legend> <div class="layui-field-box"> <div class="layui-form-item"> <div class="layui-inline"> <label class="layui-form-label" style="width:90px;">菜单名称</label> <div class="layui-input-block" style="margin-left:120px"> <input type="text" name="eumname" id="name" autocomplete="off" class="layui-input"> </div> </div> <button type="button" class="layui-btn layui-btn but" style=" margin-bottom: 4px;" id="searchButton" onclick="Search()"><i class="layui-icon layui-icon-search"></i>查询</button> <button type="button" class="layui-btn layui-bg-blue but" style=" margin-bottom: 4px;" onclick="Add()"><i class="layui-icon layui-icon-addition"></i>添加</button> </div> </div> </fieldset> <table class="layui-hide" id="ID-treeTable-demo" lay-filter="test"></table> <script type="text/html" id="TPL-treeTable-demo-tools"> <div class="layui-btn-container"> <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i>新增</a> <a class="layui-btn layui-bg-blue layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a> <a class="layui-btn layui-bg-red layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a> </div> </script> <div class="editInfo"> <form class="layui-form layui-form-pane addorgfrom" action="" lay-filter="demo-val-filter"> <input type="hidden" name="ID" /> <div class="layui-form-item"> <label class="layui-form-label" style="width:130px">模块名称</label> <div class="layui-input-block"> <input type="text" name="menuname" autocomplete="off" placeholder="请输入组织模块名称" lay-verify="required" class="layui-input" style="width:87%"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" style="width:130px">模块代码</label> <div class="layui-input-block"> <input type="text" name="menucode" autocomplete="off" placeholder="请输入组织模块代码" lay-verify="required" class="layui-input" style="width:87%"> </div> </div> <div class="layui-form-item" style="text-align:center" id="but"> <div class="layui-input-block" style="margin-left:-53px;padding:10px"> <button type="submit" class="layui-btn" lay-submit lay-filter="demo1" style="margin:10px">保存</button> <button type="reset" class="layui-btn layui-btn-primary" style="margin-left:30px;">重置</button> </div> </div> </form> </div> @*表格内的新增,编辑*@ <div class="addeditInfo"> <form class="layui-form layui-form-pane addform" action="" lay-filter="demo-val-filter"> <input type="hidden" name="ID" /> <input type="hidden" name="ParentId" /> <div class="layui-form-item"> <label class="layui-form-label" style="width:130px">上一级菜单名称</label> <div class="layui-input-block"> <input type="text" name="modulename" autocomplete="off" disabled="disabled" placeholder="请输入模块名称" lay-verify="required" class="layui-input" style="width:87%"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" style="width:130px">上一级菜单代码</label> <div class="layui-input-block"> <input type="text" name="modulecode" autocomplete="off" disabled="disabled" placeholder="请输入模块代码" lay-verify="required" class="layui-input" style="width:87%"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" style="width:120px">当前级别</label> <div class="layui-input-block" style="margin-left: 121px;width:289px"> <select name="Type" lay-verify="required" disabled="disabled"> <option value="">请选择级别</option> <option value="0">菜单</option> <option value="1">其他</option> </select> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" style="width:120px">模块名称</label> <div class="layui-input-block"> <input type="text" name="newname" autocomplete="off" placeholder="请输入模块名称" lay-verify="required" class="layui-input" style="width:90%"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" style="width:120px">模块代码</label> <div class="layui-input-block"> <input type="text" name="newcode" autocomplete="off" placeholder="请输入模块代码" lay-verify="required" class="layui-input" style="width:90%"> </div> </div> <div class="layui-form-item" style="text-align:center" id="but"> <div class="layui-input-block" style="margin-left:-53px;padding:10px"> <button type="submit" class="layui-btn" lay-submit lay-filter="demo2" style="margin:10px">保存</button> <button type="reset" class="layui-btn layui-btn-primary" style="margin-left:30px;">重置</button> </div> </div> </form> </div> <script> var SearchtreeTable; layui.use(['form', 'table'], function () { var table = layui.table; var treeTable = layui.treeTable; var layer = layui.layer; var form = layui.form; // 渲染 var inst = treeTable.render({ elem: '#ID-treeTable-demo', url: '/ResourceManage/GetList', // 此处为静态模拟数据,实际使用时需换成真实接口 cols: [[ { type: 'checkbox', }, { field: 'ID', title: 'ID', hide: true }, // 隐藏但保留数据 { field: 'ParentId', title: '父ID', hide: true }, // 隐藏但保留数据 { field: 'name', title: '模块名称', width: '20%', }, { field: 'ModuleCode', title: '模块代码', width: '20%', sort: true }, { field: 'Type', title: '级别', width: '20%', sort: true, templet: function (d) { switch (d.Type) { case 0: return "菜单"; break; case 1: return "其他"; break; default: return "其他"; break; } } }, { field: 'Url', title: '链接', width: '15%', sort: true }, { title: "操作", width: '21.5%', align: "center", toolbar: "#TPL-treeTable-demo-tools" } ]], tree: { iconIndex: 1, // 图标显示在第 2 列(对应“组织机构名称”列,索引从 0 开始) isParent: 'isParent', // 绑定后台的 `isParent` 字段(标识是否有子节点) // 删除 async 配置!后台已返回完整 children 数组,无需异步加载 }, page: true }); SearchtreeTable = inst; //新增,编辑,删除 table.on('tool(test)', function (obj) { // 双击 toolDouble var data = obj.data; // 获得当前行数据 // console.log(obj) if (obj.event === 'add') { //新增子集 layer.open({ type: 1, // page 层类型 area: ['550px', '480px'], title: '新增资源模块', shade: 0.6, // 遮罩透明度 shadeClose: false, // 点击遮罩区域,关闭弹层 maxmin: false, // 允许全屏最小化 anim: 0, // 0-6 的动画形式,-1 不开启 content: $(".addeditInfo").html() }); //赋值 form.val('demo-val-filter', { "modulename": data.name, "modulecode": data.ModuleCode, "Type": data.Type, "ID": null, "ParentId": data.ID }); } else if (obj.event === 'edit') { //编辑 //修改编辑职位 layer.open({ type: 1, area: ['550px', '480px'], title: '编辑资源模块', shade: 0.6, // 遮罩透明度 shadeClose: false, // 点击遮罩区域,关闭弹层 maxmin: false, // 允许全屏最小化 anim: 0, // 0-6 的动画形式,-1 不开启 content: $('.addeditInfo').html(), success: function () { $.ajax({ url: '/ResourceManage/GetEditData', data: { nodeId: data.ID }, success: function (res) { // 填充数据,处理父节点不存在的情况 form.val('demo-val-filter', { "modulename": res.parentName || data.name, // 父节点不存在时显示自身名称 "modulecode": res.parentCode || data.ModuleCode, // 父节点不存在时显示自身代码 "Type": data.Type, "newname": data.name, "newcode": data.ModuleCode, "ID": res.ID, "ParentId": res.parentID }); } }); } }); } else { layer.confirm('真的删除行 [' + data.name + '] 么', function (index) { obj.del(); // 删除对应行(tr)的DOM结构 layer.close(index); // 向服务端发送删除指令 $.ajax({ url: '/ResourceManage/DelInfo', type: 'post', data: { id: data.ID }, success: function (res) { if (res.code == 0) { layer.msg(res.msg, { icon: 6, time: 1500 }, function () { Search(); }) } else { layer.msg(res.msg, { icon: 5, time: 1500 }) } } }) }); } }); // 提交事件 form.on('submit(demo1)', function (data) { var field = data.field; // 获取表单字段值 // 此处可执行 Ajax 等操作 $.ajax({ url: '/ResourceManage/Add', type: 'post', data: field, success: function (res) { if (res.code == 0) { layer.msg(res.msg, { icon: 6, time: 3000 }, function () { layer.closeAll(); // 关闭所有类型的层 Search(); }); } else { layer.msg(res.msg, { icon: 5, time: 2000 }); } } }) return false; // 阻止默认 form 跳转 }); // 提交事件 form.on('submit(demo2)', function (data) { var field = data.field; // 获取表单字段值 var leve = data.leve; var ID = data.ID; var ParentId = data.ParentId; // 此处可执行 Ajax 等操作 $.ajax({ url: '/ResourceManage/AddTreeInfo', type: 'post', data: { newname: field.newname, newcode: field.newcode, Type: field.Type, ID: field.ID, pid: field.ParentId }, success: function (res) { if (res.code == 0) { layer.msg(res.msg, { icon: 6, time: 3000 }, function () { layer.closeAll(); // 关闭所有类型的层 Search(); }); } else { layer.msg(res.msg, { icon: 5, time: 2000 }); } } }) return false; // 阻止默认 form 跳转 }); }); //重载,模糊查询 //重载,模糊查询 function Search() { var nameVal = $('input[name="eumname"]').val().trim(); // 完整重载 - 所有属性属性(options)均可参与到重载中 SearchtreeTable.reload({ where: { // 传递数据异步请求时携带的字段 eumname: nameVal, }, }); } //添加 function Add() { // 在此处输入 layer 的任意代码 layer.open({ type: 1, // page 层类型 area: ['550px', '350px'], title: '新增资源模块', shade: 0.6, // 遮罩透明度 shadeClose: true, // 点击遮罩区域,关闭弹层 maxmin: true, // 允许全屏最小化 anim: 0, // 0-6 的动画形式,-1 不开启 content: $(".editInfo").html() }); } </script> </body> </html> using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; using System.Web.Mvc; using WebApplication1.Models; namespace WebApplication1.Controllers { [LoginActionFitter] public class ResourceManageController : Controller { AoutEntities1 db = new AoutEntities1(); ReturnJsonData jsonData = new ReturnJsonData(); ReturnListJsonData orgTreeList = new ReturnListJsonData(); // GET: public ActionResult Index() { return View(); } #region 查询 /// <summary> /// 模糊查询 /// </summary> /// <param name="page"></param> /// <param name="limit"></param> /// <param name="orgname"></param> /// <returns></returns> public ActionResult GetList(int page, int limit, string eumname) { //返回树形表格 List<object> retultlist = new List<object>(); //第一步 查找所有的一级菜单 var list = db.SystemResourceModule.Where(a => a.ParentId == Guid.Empty).ToList(); if (!string.IsNullOrEmpty(eumname)) { list = db.SystemResourceModule.Where(a => a.ModuleName.Contains(eumname)).ToList(); foreach (var itme in list) { ReturnMenuListData obj = new ReturnMenuListData(); obj.ID = itme.ID; obj.ParentId = itme.ParentId; obj.name = itme.ModuleName; obj.ModuleCode = itme.ModuleCode; obj.Url = itme.Url; obj.Type = itme.Type; obj.CreateDate = itme.CreateDate; obj.ModifyDate = itme.ModifyDate; //验证是否还有有子集 obj.isParent = false; obj.children = null; retultlist.Add(obj); } } else { list = db.SystemResourceModule.Where(a => a.ParentId == Guid.Empty).ToList(); //循环 foreach (var itme in list) { ReturnMenuListData obj = new ReturnMenuListData(); obj.ID = itme.ID; obj.ParentId = itme.ParentId; obj.name = itme.ModuleName; obj.ModuleCode = itme.ModuleCode; obj.Url = itme.Url; obj.Type = itme.Type; obj.CreateDate = itme.CreateDate; obj.ModifyDate = itme.ModifyDate; //验证是否还有有子集 obj.isParent = db.SystemResourceModule.Where(a => a.ParentId == itme.ID).ToList().Count > 0 ? true : false; if (obj.isParent == true) { //查找所以子集 obj.children = BuildTree(list, itme.ID); } retultlist.Add(obj); } } orgTreeList.code = 0; orgTreeList.count = list.Count; orgTreeList.data = retultlist; return Json(orgTreeList, JsonRequestBehavior.AllowGet); } #endregion #region 递归调用 /// <summary> /// 递归调用 /// </summary> /// <param name="list"></param> /// <param name="ID"></param> /// <returns></returns> private List<object> BuildTree(List<SystemResourceModule> list, Guid ID) { List<object> Treelist = new List<object>(); List<SystemResourceModule> childList = db.SystemResourceModule.Where(a => a.ParentId == ID).ToList(); //循环 foreach (var itme in childList) { ReturnMenuListData obj = new ReturnMenuListData(); obj.ID = itme.ID; obj.ParentId = itme.ParentId; obj.name = itme.ModuleName; obj.ModuleCode = itme.ModuleCode; obj.Url = itme.Url; obj.CreateDate = itme.CreateDate; obj.ModifyDate = itme.ModifyDate; obj.isParent = db.SystemResourceModule.Where(a => a.ParentId == itme.ID).ToList().Count > 0 ? true : false; obj.children = BuildTree(childList, itme.ID); Treelist.Add(obj); } return Treelist; } #endregion #region 查询父级及子集信息 public ActionResult GetEditData(Guid nodeId) { var current = db.SystemResourceModule.Find(nodeId); if (current == null) return Json(new { success = false }); // 总公司的ParentId为null或自身(假设总公司ParentId=0或null) var isRoot = current.ParentId == null || current.ParentId == Guid.Empty; var parent = isRoot ? current : db.SystemResourceModule.Find(current.ParentId); return Json(new { parentName = parent.ModuleName, parentCode = parent.ModuleCode, Type = current.Type, orgName = current.ModuleName, orgCode = current.ModuleCode, ID = current.ID, parentID = current.ParentId, }, JsonRequestBehavior.AllowGet); } #endregion #region 删除 /// <summary> /// 删除操作 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult DelInfo(Guid? id) { if (id == null) { jsonData.code = 1; jsonData.msg = "删除失败,未找到当行数据"; } else { //删除 var entity = db.SystemResourceModule.Find(id); if (entity == null) { jsonData.code = 1; jsonData.msg = "删除失败,未找到当前行数据"; } else { db.SystemResourceModule.Remove(entity); var result = db.SaveChanges(); if (result > 0) { jsonData.code = 0; jsonData.msg = "删除成功"; } else { jsonData.code = 1; jsonData.msg = "删除失败,请联系管理员"; } } } return Json(jsonData, JsonRequestBehavior.AllowGet); } #endregion #region 新增菜单 /// <summary> /// 新增,修改 /// </summary> /// <returns></returns> public ActionResult Add(SystemResourceModule org, string menuname, string menucode) { org.ModuleName = menuname; org.ModuleCode = menucode; org.ID = Guid.NewGuid(); org.Type = 0; org.ParentId = Guid.Empty; org.CreateDate = DateTime.Now; org.ModifyDate = DateTime.Now; db.SystemResourceModule.Add(org); var result = db.SaveChanges(); if (result > 0) { jsonData.code = 0; jsonData.msg = "新增资源模块成功"; } else { jsonData.code = 1; jsonData.msg = "新增失败,请联系管理员"; } return Json(jsonData, JsonRequestBehavior.AllowGet); } #endregion #region 新增修改 /// <summary> /// 新增,修改 /// </summary> /// <returns></returns> public ActionResult AddTreeInfo(string newname, string newcode, int? Type, Guid? ID, Guid pid) { if (ID == null || ID == Guid.Empty) { // 新增逻辑:parentId为父节点ID(新增时需传递) var newOrg = new SystemResourceModule { ID = Guid.NewGuid(), ParentId = pid, ModuleName = newname, ModuleCode = newcode, Type = Type + 1, CreateDate = DateTime.Now, ModifyDate = DateTime.Now }; db.SystemResourceModule.Add(newOrg); } else { // 编辑逻辑:通过ID查找当前行(确保是当前行,而非总公司,依赖ID唯一性) var entity = db.SystemResourceModule.Find(ID); if (entity != null) { entity.ModuleName = newname; entity.ModuleCode = newcode; entity.ModifyDate = DateTime.Now; db.Entry(entity).State = EntityState.Modified; } } var result = db.SaveChanges(); if (result > 0) { jsonData.code = 0; jsonData.msg = "保存成功"; } else { jsonData.code = 1; jsonData.msg = "保存失败,请联系管理员"; } return Json(jsonData, JsonRequestBehavior.AllowGet); } #endregion } }检查错误
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值