123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- define(['jquery'], function($) {
- // 测试
- /**
- * ajax请求函数
- * @param {string} type 请求类型post/get
- * @param {string} url 请求地址
- * @param {string} data 请求数据
- * @param {func} successFunc 成功回掉函数
- * @return {null}
- */
- function ajaxFunc(type, url, data, successFunc) {
- console.log('chen',data);
- $.ajax({
- type: type,
- dataType: 'json',
- contentType : 'application/json;charset=utf-8',
- url: config.baseUrl + url,
- data: data,
- success: function(e) {
- successFunc(e);
- },
- error: function(e) {
- console.log(e);
- }
- });
- }
- /**
- * 渲染window窗口
- * @param {string} selector 窗口selector
- * @param {object} config 配置文件
- * @return {null} [description]
- */
- function renderwindow(selector, config) {
- var defaultConfig = {
- width: 600,
- height: 400,
- modal: true,
- closed: true,
- collapsible: false,
- minimizable: false,
- maximizable: false,
- title: '默认提示框'
- };
- var compConfig = $.extend(defaultConfig, config);
- $(selector).window(compConfig);
- }
- function listType(selector, url, formatter, condition) {
- $(selector).combobox({
- url: url,
- valueField: 'id',
- textField: 'name',
- queryParams: condition,
- loadFilter: function(e) {
- switch(formatter) {
- case 0:
- return e.data;
- case 1:
- return e.data.list;
- }
- }
- });
- }
- /**
- * ajax请求后的提示
- * @param {object} e 请求返回事件
- * @param {string} wSelector 弹出框的类
- * @param {string} cSelector 数据表格的类
- * @param {string} mode 请求的模式,是否需要关闭window需要:0,不需要:1
- * @return {null} [description]
- */
- function requestTip(e, wSelector, cSelector, mode) {
- if (e.code === 0) {
- $.messager.alert('提示', e.msg, 'info');
- if (mode === 0) {
- $(wSelector).window('close');
- }
- $(cSelector).datagrid('reload');
- } else {
- $.messager.alert('警告', e.msg, 'error');
- }
- }
- function delInfo(selector, url, wSelector) {
- $(selector).on('click', function(e) {
- e.preventDefault();
- var id = $(this).data('id');
- $.messager.confirm('提示', '确认删除', function(e) {
- if (e) {
- base.ajaxFunc('get', url, {id:id},function(e) {
- base.requestTip(e, 'wSelector', wSelector, 1);
- });
- }
- });
- });
- }
- //切换选中样式
- function switchActive(selector) {
- $(selector).on('click', function(e) {
- e.preventDefault();
- $(this).addClass('active').siblings().removeClass('active');
- var href = $(this).data('href');
- $('.bif-con').load(href, function(e) {
- });
- });
- }
- return {
- ajaxFunc: ajaxFunc,
- renderwindow: renderwindow,
- listType: listType,
- requestTip: requestTip,
- delInfo: delInfo,
- switchActive: switchActive
- };
- });
|