⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 user.js

📁 图书管理系统
💻 JS
📖 第 1 页 / 共 2 页
字号:
// 用户管理
var User = Ext.data.Record.create([
	{name : 'userId',mapping : 'userId',type : 'int'}, 
	{name : 'emplName',mapping : 'emplName',type : 'string'}, 
	{name : 'emplNo',mapping : 'emplNo',type : 'string'}, 
	{name : 'mobilePhone',mapping : 'mobilePhone',type : 'string'}, 
	{name : 'sex',mapping : 'sex',type : 'string'}, 
	{name : 'age',mapping : 'age',type : 'int'}, 
	{name : 'userName',mapping : 'userName',type : 'string'}, 
	{name : 'password',mapping : 'password',type : 'string'}, 
	{name : 'userId',mapping : 'userId',type : 'int'}, 
	{name : 'userName',mapping : 'userName',type : 'string'}, 
	{name : 'deptId',mapping : 'deptId',type : 'int'}, 
	{name : 'deptName',mapping : 'deptName',type : 'string'}, 
	{name : 'dutyId',mapping : 'dutyId',type : 'int'}, 
	{name : 'dutyName',mapping : 'dutyName',type : 'string'}, 
	{name : 'manager',mapping : 'manager',type : 'bool'}, 
	{name : 'remark',mapping : 'remark',type : 'string'}]);

var ds_duty_select = new Ext.data.Store({
	url : 'findAllDuty.action',
	reader : new Ext.data.JsonReader({root : 'root'}, 
	[{name : 'dutyId'}, {name : 'dutyName'}])
});

var ds_dept_select = new Ext.data.Store({
	url : 'findDeptByCompany.action',
	reader : new Ext.data.JsonReader({root : 'root'}, 
	[{name : 'deptId'}, {name : 'deptName'}])
});

Ext.grid.CheckColumn = function(config) {
	Ext.apply(this, config);
	if (!this.id) {
		this.id = Ext.id();
	}
	this.renderer = this.renderer.createDelegate(this);
};

Ext.grid.CheckColumn.prototype = {
	init : function(grid) {
		this.grid = grid;
		this.grid.on('render', function() {
			var view = this.grid.getView();
			view.mainBody.on('mousedown', this.onMouseDown, this);
		}, this);
	},

	onMouseDown : function(e, t) {
		if (t.className && t.className.indexOf('x-grid3-cc-' + this.id) != -1) {
			e.stopEvent();
			var index = this.grid.getView().findRowIndex(t);
			var cindex = this.grid.getView().findCellIndex(t);
			var record = this.grid.store.getAt(index);
			var field = this.grid.colModel.getDataIndex(cindex);
			var e = {
				grid : this.grid,
				record : record,
				field : field,
				originalValue : record.data[this.dataIndex],
				value : !record.data[this.dataIndex],
				row : index,
				column : cindex,
				cancel : false
			};
			if (this.grid.fireEvent("validateedit", e) !== false && !e.cancel) {
				delete e.cancel;
				record.set(this.dataIndex, !record.data[this.dataIndex]);
				this.grid.fireEvent("afteredit", e);
			}
		}
	},

	renderer : function(v, p, record) {
		p.css += ' x-grid3-check-col-td';
		return '<div class="x-grid3-check-col' + (v ? '-on' : '') + ' x-grid3-cc-' + this.id + '">&#160;</div>';
	}
};

var checkColumn = new Ext.grid.CheckColumn({
	header : "管理员?",
	dataIndex : 'manager',
	width : 55
});

var cm_user = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
	header : '用户名',
	width : 85,
	dataIndex : 'userName'
}, {
	header : '密码',
	width : 85,
	dataIndex : 'password',
	sortable : false,
	menuDisabled : true,
	editor : new Ext.form.TextField({
		allowBlank : false,
		minLength : 6,
		maxLength : 20
	})
}, {
	header : '用户姓名',
	sortable : false,
	menuDisabled : true,
	width : 90,
	dataIndex : 'emplName',
	editor : new Ext.form.TextField({
		allowBlank : false,
		maxLength : 20
	})
}, {
	header : '用户编码',
	width : 85,
	dataIndex : 'emplNo',
	hidden : true,
	menuDisabled : true,
	editor : new Ext.form.TextField({
		maxLength : 20
	})
}, {
	header : '手机号码',
	width : 85,
	dataIndex : 'mobilePhone',
	menuDisabled : true,
	editor : new Ext.form.TextField({
		maxLength : 20
	})
}, {
	header : '性别',
	width : 60,
	dataIndex : 'sex',
	hidden : true,
	sortable : false,
	menuDisabled : true,
	editor : new Ext.form.ComboBox({
		mode : 'local',
		editable : false,
		store : new Ext.data.SimpleStore({
			data : [['男', '男'], ['女', '女']],
			fields : ['text', 'value']
		}),
		displayField : 'text',
		valueField : 'value',
		mode : 'local',
		triggerAction : 'all'
	})
}, {
	header : '年龄',
	width : 40,
	dataIndex : 'age',
	sortable : false,
	hidden : true,
	menuDisabled : true,
	editor : new Ext.form.NumberField({
		decimalPrecision : 1,
		fieldLabel : '年龄',
		maxLength : 3,
		maxLengthText : '年龄不符合实际',
		maxValue : 120,
		maxText : '最大允许年龄为120岁'
	})
}, {
	header : '所属分公司',
	width : 85,
	sortable : false,
	dataIndex : 'companyName',
	menuDisabled : true,
	editor : new Ext.form.ComboBox({
		store : ds_company_select,
		displayField : 'companyName',
		valueField : 'companyName',
		mode : 'remote',
		allowBlank : false,
		editable : false,
		triggerAction : 'all',
		listWidth : 130,
		listeners : {
			'select' : function(combo, record) {
				companyId = record.data.companyId;
				ds_dept_select.baseParams.companyId = companyId;
				ds_dept_select.reload();
			}
		}
	})
}, {
	header : '所属部门',
	width : 85,
	dataIndex : 'deptName',
	sortable : false,
	menuDisabled : true,
	editor : new Ext.form.ComboBox({
		valueField : 'deptName',
		displayField : 'deptName',
		mode : 'remote',
		store : ds_dept_select,
		editable : false,
		allowBlank : false,
		triggerAction : 'all',
		listWidth : 130,
		listeners : {
			'select' : function(combo, record) {// 当选择部门后,获得部门的id保存到全局
				deptId = record.data.deptId;
			},
			'beforequery' : function(queryEvent) {// 在执行下拉查询时,先判断是否参数companyId(单击行时被附值,更换分公司也被赋值)是否存在
				if (!companyId) {
					queryEvent.cancel = true;
				}
			},
			'focus' : function() {
				// 当获得焦点时,设置查询参数,重新加载数据,注意:如果不是每次参数都有可能不一样,不推荐使用这个监听器
				// 因为它每次都要重新加载数据
				ds_dept_select.baseParams.companyId = companyId;
				ds_dept_select.reload();
			}
		}
	})
}, {
	header : '职称',
	width : 85,
	dataIndex : 'dutyName',
	menuDisabled : true,
	sortable : false,
	editor : new Ext.form.ComboBox({
		store : ds_duty_select,
		displayField : 'dutyName',
		valueField : 'dutyName',
		mode : 'remote',
		allowBlank : false,
		editable : false,
		triggerAction : 'all',
		listWidth : 100,
		listeners : {
			'select' : function(combo, record) {
				dutyId = record.data.dutyId;
			}
		}
	})
}, checkColumn, {
	header : '备注',
	id : 'remark',
	dataIndex : 'remark',
	menuDisabled : true,
	sortable : false,
	editor : new Ext.form.TextField({
		maxLength : 200
	})
}]);

cm_user.defaultSortable = true;

var btn_add_user = new Ext.Button({
	text : '添加用户',
	iconCls : 'icon-add',
	handler : function() {
		window_add_user.show();
	}
});

var btn_del_user = new Ext.Button({
	text : '删除用户',
	iconCls : 'icon-del',
	handler : function() {
		var record = grid_user.getSelectionModel().getSelected();
		if (record) {
			Ext.Msg.confirm('确认删除', '你确定删除该条记录?', function(btn) {
				if (btn == 'yes') {
					Ext.Ajax.request({
						url : 'deleteUser.action',
						params : {userId : record.data.userId},
						success : function() {grid_user.getStore().remove(record);},
						failure : function() {
							Ext.Msg.show({
								title : '错误提示',
								msg : '删除时发生错误!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR
							});
						}
					});
				}
			});
		}
	}
});

var text_search_user = new Ext.form.TextField({
	name : 'textSearchUser',
	width : 200,
	emptyText : '请输入查询条件!!!!',
	listeners : {
		'specialkey' : function(field, e) {
			if (e.getKey() == Ext.EventObject.ENTER) {
				searchUser();
			}
		}
	}
});

var searchUser = function() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -