| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- Ext.define('saas.util.BaseUtil', {
- statics: {
- /**
- * 打开/切换到新页签
- * @param xtype: view xtype
- * @param title: 标题
- * @param id: id
- * @param config: 绑定到view的其他配置
- */
- openTab: function (xtype, title, id, config) {
- var mainTab = Ext.getCmp('main-tab-panel');
- var panel = mainTab.query('[tabId="' + id + '"]')[0];
- if (!panel) {
- panel = Ext.create('saas.view.core.tab.Panel', {
- tabId: id,
- title: title,
- viewType: xtype,
- viewConfig: config
- });
- Ext.suspendLayouts();
- mainTab.setActiveTab(mainTab.add(panel));
- Ext.resumeLayouts(true);
- } else {
- panel.viewConfig = config;
- mainTab.setActiveTab(panel);
- }
- },
- /**
- * 重设tab标题
- */
- refreshTabTitle: function (id, title) {
- var currentTab = this.getCurrentTab();
- currentTab.tabId = id;
- currentTab.setTitle(title);
- },
- /**
- * 获得当前Tab
- */
- getCurrentTab: function () {
- var mainTab = Ext.getCmp('main-tab-panel');
- var currentTab = mainTab.getActiveTab();
- return currentTab;
- },
- /**
- * 显示toast提示(无需用户操作)
- * @param content: 内容
- * @param title: 标题
- *
- */
- showSuccessToast: function (content, title, configs) {
- Ext.toast(Ext.Object.merge({
- cls:'x-toast-success',
- html: content,
- title: title,
- closable: false,
- align: 't',
- autoCloseDelay:3000,
- autoClose:true,
- maxWidth: 400
- }, configs));
- },
- showErrorToast: function (content, title, configs) {
- Ext.toast(Ext.Object.merge({
- cls:'x-toast-error',
- html: content,
- title: title,
- closable: false,
- align: 't',
- autoCloseDelay:3000,
- autoClose:true,
- maxWidth: 400
- }, configs));
- },
- /**
- * 显示警告(需要选择是、否)
- * @param title: 标题
- * @param message: 内容
- * @return : Promise
- */
- showConfirm: function (title, message) {
- return new Ext.Promise(function (resolve, reject) {
- Ext.MessageBox.confirm(title, message, function (buttonId) {
- return resolve(buttonId);
- });
- })
- },
- warnMsg: function (msg, fn) {
- Ext.MessageBox.show({
- title: '提示',
- msg: msg,
- buttons: Ext.Msg.YESNO,
- icon: Ext.Msg.WARNING,
- fn: fn
- });
- },
- deleteWarn: function (msg, fn) {
- Ext.MessageBox.show({
- title: '提示',
- msg: msg || '确定要删除当前表单?',
- buttons: Ext.Msg.YESNO,
- icon: Ext.Msg.WARNING,
- fn: fn,
- renderTo: Ext.getCmp('main-tab-panel').getActiveTab().getEl()
- });
- },
- /**
- * 判断字符串是否日期字符串
- * 需要满足格式 yyyy-MM-dd hh:mm:ss
- * 或者yyyy-M-d h:m:s
- * @param str: 字符串
- * @returns Boolean
- */
- isDateString: function (str) {
- return (/^(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/).test(str);
- },
- getCurrentUser: function () {
- return saas.util.State.get('session') ? saas.util.State.get('session').account : {};
- },
- /**
- * 发起Ajax请求
- * @param config: 请求参数
- */
- request: function (config) {
- var url = config.url,
- params = config.params,
- async = config.async || true,
- method = config.method || 'GET',
- timeout = config.timeout || 8000,
- defaultHeaders = {
- 'Access-Control-Allow-Origin': '*',
- "Content-Type": 'application/json;charset=UTF-8'
- };
- return new Ext.Promise(function (resolve, reject) {
- Ext.Ajax.request({
- url: url,
- params: params,
- async: async,
- method: method,
- timeout: timeout,
- headers: Ext.apply(defaultHeaders, config.headers),
- success: function (response, opts) {
- var res = Ext.decode(response.responseText);
- if (res.success) {
- return resolve(res);
- } else {
- console.error('server request failure with code ' + res.code + '.');
- console.error('failure message: ' + res.message);
- return reject(res);
- }
- },
- failure: function (response, opts) {
- console.error('server-side failure with status code ' + response);
- return reject(response);
- }
- });
- })
- },
- }
- });
|