';
});
});
};
WidgetDesign.prototype.iframeRender = function (sender) {
var that = this;
var iframe = $(sender.el.dom).find('iframe')[0];
iframe.contentWindow['designer'] = that;
iframe.contentWindow['editorInitFn'] = function (editorUi) {
editorUi.actions.get('save').funct = that.onFileSave.bind(that);
editorUi.actions.get('saveAs').funct = that.onFileSaveAs.bind(that);
editorUi.actions.get('open').visible = false;
editorUi.actions.get('new').visible = false;
editorUi.actions.get('preview').visible = false;
editorUi.actions.get('print').visible = false;
editorUi.actions.get('pageSetup').visible = false;
editorUi.actions.get('help').visible = false;
editorUi.actions.get('export').visible = false;
editorUi.actions.get('about').visible = false;
editorUi.menus.menus.help.setEnabled(false);
that.editorUi = editorUi;
that.mxUtils = iframe.contentWindow['mxUtils'];
if (that.layoutCode) {
that.reload();
}
};
};
WidgetDesign.prototype.onDestroy = function () {
var _a;
try {
(_a = this.editorUi) === null || _a === void 0 ? void 0 : _a.destroy();
}
catch (e) {
}
};
WidgetDesign.prototype.onFileSaveAs = function () {
var _this = this;
this.showSaveAsDlg({ code: this.layoutCode, name: this.layoutName })
.then(function (_a) {
var code = _a.code, name = _a.name;
_this.layoutCode = code;
_this.layoutName = name;
_this.onSave();
});
};
WidgetDesign.prototype.onSave = function () {
var _this = this;
var layoutContent = this.editorUi.getEditBlankXml();
var layoutCode = this.layoutCode;
var layoutName = this.layoutName;
if (!layoutCode || !layoutName) {
msg$1('图形编号和图形名称必填');
return;
}
this.viewModel.set('title', this.layoutName + ' [' + this.layoutCode + ']');
this.setLoading(true);
saveWhLayout({
layoutCode: layoutCode, layoutName: layoutName, layoutContent: layoutContent
}).then(function (res) {
msg$1(res.msg);
handles$1.whLayout.reload();
}).finally(function () {
_this.setLoading(false);
});
};
WidgetDesign.prototype.onFileSave = function () {
if (!this.layoutCode || !this.layoutName) {
this.onFileSaveAs();
}
else {
this.onSave();
}
};
WidgetDesign.prototype.showSaveAsDlg = function (_a) {
var code = _a.code, name = _a.name;
return new Promise(function (resolve, reject) {
var viewModel = new Ext.app.ViewModel({
data: {
code: code !== null && code !== void 0 ? code : '',
name: name !== null && name !== void 0 ? name : '',
}
});
var dlg = Ext.create('Ext.window.Window', {
title: '保存',
viewModel: viewModel,
layout: {
type: "vbox",
pack: "start",
align: "stretch"
},
items: [
{
xtype: 'textfield', fieldLabel: '图编号', margin: '0 15 15 0',
bind: '{code}'
},
{
xtype: 'textfield', fieldLabel: '图名称', margin: '0 15 15 0',
bind: '{name}'
}
],
fbar: [
{
xtype: 'button', text: '保存', iconCls: 'x-fa fa-save', listeners: {
click: function () {
var code = viewModel.get('code');
var name = viewModel.get('name');
resolve({ code: code, name: name });
dlg.close();
}
}
},
{
xtype: 'button', text: '取消', iconCls: 'x-fa fa-times', listeners: {
click: function () {
dlg.close();
}
}
},
]
});
dlg.show();
});
};
return WidgetDesign;
}(Scope));
// init()
var Workbench = /** @class */ (function (_super) {
__extends(Workbench, _super);
// activeModulePage: ModulePage = null
function Workbench() {
var _this = _super.call(this, { model: model$c, vjson: vjson$c }) || this;
_this.name = "MainWindow";
_this.modules = [];
_this.yvgridDesign = null;
return _this;
}
Workbench.prototype.leftTabChange = function (tabPanel, newCard, oldCard) {
if (newCard) {
this.viewModel.set('leftTabTitle', newCard.tooltip);
}
else {
this.viewModel.set('leftTabTitle', '未选中');
}
};
Object.defineProperty(Workbench.prototype, "activeModulePage", {
get: function () {
var _a;
return ((_a = window['mainWindow'].refs.tt.getActiveTab()) === null || _a === void 0 ? void 0 : _a.yvanScope) || undefined;
},
enumerable: true,
configurable: true
});
Workbench.prototype.documentKeydown = function (event) {
if (event.ctrlKey || event.metaKey) {
if (event.key.toLowerCase() === 's') {
eventBus.publish(EventType.SaveCall, {});
event.stopPropagation();
event.preventDefault();
}
else if (event.key.toLowerCase() === 'z') {
if (event.shiftKey) {
eventBus.publish(EventType.Redo, {});
event.stopPropagation();
event.preventDefault();
}
else {
eventBus.publish(EventType.Undo, {});
event.stopPropagation();
event.preventDefault();
}
}
}
};
Workbench.prototype.onLoad = function () {
var _this = this;
window["tt"] = this.refs['tt'];
window["vm"] = this.viewModel;
$('#loading').remove();
setMainWindow(this);
setStatusbar(this.down('statusbar'));
document.addEventListener('keydown', this.documentKeydown.bind(this));
var currentProject = getCurrentProject();
this.viewModel.set("currentProject", (currentProject === null || currentProject === void 0 ? void 0 : currentProject.url) + "(" + (currentProject === null || currentProject === void 0 ? void 0 : currentProject.name) + ")");
// handles.fileTree.reload()
eventBus.subscribe(EventType.ModuleOpen, function (rawData) {
_this.showModule(rawData);
});
eventBus.subscribe(EventType.Undo, function () {
_this.onUndo();
});
eventBus.subscribe(EventType.Redo, function () {
_this.onRedo();
});
eventBus.subscribe(EventType.Cut, function (_a) {
var a = _a.a, b = _a.b, c = _a.c, d = _a.d;
_this.onCut(a, b, c, d);
});
eventBus.subscribe(EventType.Copy, function (_a) {
var a = _a.a, b = _a.b, c = _a.c, d = _a.d;
_this.onCopy(a, b, c, d);
});
eventBus.subscribe(EventType.Paste, function (_a) {
var a = _a.a, b = _a.b, c = _a.c, d = _a.d;
_this.onPaste(a, b, c, d);
});
eventBus.subscribe(EventType.SelectAll, function () {
_this.onSelectAll();
});
eventBus.subscribe(EventType.SelectAll, function () {
_this.onSelectAll();
});
eventBus.subscribe(EventType.RunCheckModule, function () {
_this.runCheckModule();
});
eventBus.subscribe(EventType.StopCheckModule, function () {
_this.stopCheckModule();
});
eventBus.subscribe(EventType.ComponentContextmenu, function (args) {
_this.onCompoentContextMenu(args);
});
this.runCheckModule();
};
Workbench.prototype.onCompoentContextMenu = function (args) {
var _this = this;
if (!this.yvgridDesign) {
this.yvgridDesign = new YvgridDesign(this.activeModulePage.moduleId);
this.yvgridDesign.showDialog(null, {}, {});
var fn_1 = this.yvgridDesign.onDestroy.bind(this.yvgridDesign);
this.yvgridDesign.onDestroy = function () {
fn_1();
_this.yvgridDesign = null;
};
}
};
Workbench.prototype.runCheckModule = function () {
var _this = this;
if (this.checkTimer) {
return;
}
this.checkTimer = setInterval(function () {
var _a;
if ((_a = _this.activeModulePage) === null || _a === void 0 ? void 0 : _a.check) {
_this.activeModulePage.check();
}
}, 5000);
};
Workbench.prototype.showWidget = function (widgetPath, widgetName, successCallback) {
var dlg = new WidgetDesign(widgetPath, widgetName);
dlg.showPage({
id: 'widget_' + widgetPath,
path: 'widget_' + widgetPath,
}, {
data: {
title: widgetPath ? '检索框:' + widgetName : '新建检索框',
}
});
dlg.dialogSuccess = successCallback;
};
Workbench.prototype.stopCheckModule = function () {
clearInterval(this.checkTimer);
this.checkTimer = null;
};
Workbench.prototype.showDataSync = function () {
var ins = new DbSync();
ins.showPage({
id: 'db_sync__',
path: 'db_sync__',
}, {
data: {}
});
};
/**
* 打开一个项目
*/
Workbench.prototype.openProject = function (project) {
setCurrentProject(project);
this.viewModel.set("currentProject", (project === null || project === void 0 ? void 0 : project.url) + "(" + (project === null || project === void 0 ? void 0 : project.name) + ")");
handles$1.fileTree.reload();
};
/**
* 打开模板开发面板
*/
Workbench.prototype.showTemplateDev = function () {
var ins = new TemplateDev();
ins.showPage({
id: 'template_dev__',
path: 'template_dev__',
}, {
data: {}
});
};
Workbench.prototype.openScope = function () {
};
/**
* 显示字段域管理器
*/
Workbench.prototype.showColumnDomain = function () {
var instance = new DbDomain();
instance.showPage({
id: 'domain__',
path: 'domain__',
}, {
data: {}
});
};
/**
* 显示性能统计
*/
Workbench.prototype.showPerform = function () {
// const instance = new PerformStats()
// instance.showPage({
// id: 'perform__',
// path: 'perform__',
//
// }, {
// data: {}
// })
};
/**
* 显示数据库代码模板库
*/
Workbench.prototype.showDbCodeTemplate = function () {
// const instance = new DbCodeTemplate()
// instance.showPage({
// id: 'dbcode__',
// path: 'dbcode__',
//
// }, {
// data: {}
// })
};
/**
* 显示数据库代码模板库
*/
Workbench.prototype.showReport = function (report_id, report_name, success) {
var instance = new ReportDesign();
instance.showPage({
id: 'report_' + report_id,
path: 'report_' + report_id,
}, {
data: {
report_id: report_id,
report_name: report_name,
}
});
instance.dialogSuccess = success;
};
/**
* 显示报表
*/
Workbench.prototype.showReportPreview = function (report_id, instance) {
instance.showPage({
id: 'REPORT__' + report_id,
path: 'REPORT__' + report_id,
}, {
data: {
report_id: report_id,
}
});
var reportName = instance.viewModel.get('report_name');
instance.viewModel.set('report_name', '[预览]-' + reportName);
};
/**
* 显示运维页面
*/
Workbench.prototype.showDevOpsTerminal = function (opsId, name, success) {
// const instance = new DevOpsTerminal()
// instance.showPage({
// id: 'ops_' + opsId,
// path: 'ops_' + opsId,
//
// }, {
// data: {
// opsId: opsId,
// name: name,
// }
// })
// instance.dialogSuccess = success
};
/**
* 显示表结构
* tableName 为空的情况就是新建表,否则就是要编辑的表
* columnName 可以为空
*/
Workbench.prototype.showTableColumn = function (schemaName, tableName, columnName, isCreate) {
var id = 'tableColumn_' + tableName;
var isCreateTable = false;
// /ROOT/schema$public/schema$public$bas_location_group_rel
var locatPath = "/ROOT/schema$" + schemaName + "/schema$" + schemaName + "$" + tableName;
if (!tableName) {
id = _$2.uniqueId('new_table');
tableName = id;
isCreateTable = true;
}
var instance = new DbColumn(schemaName, tableName, columnName, isCreateTable, isCreate);
instance.showPage({
id: id,
path: id,
locatPath: locatPath
}, {
data: {
tableName: tableName,
columnName: columnName
}
});
};
/**
* 打开某个模块
* 例如: com/galaxis/wms/inbound/cmd_in/CmdIn
*/
Workbench.prototype.showModule = function (rawData) {
var id = rawData.id, path = rawData.path;
var separator = '/';
var idx = _$2.findIndex(this.modules, function (item) { return item.path + separator + item.name === path; });
var module = this.modules[idx];
var pageId = path.replaceAll('/', '_');
console.log('open module', module);
var instance = new ModulePage(id, module);
eventBus.publish(EventType.ModulePageCreate, __assign(__assign({}, rawData), { modulePage: instance }));
instance.showPage({
id: 'module_' + pageId,
path: path,
title: module.name
}, {
data: {}
});
};
Workbench.prototype.showBmpnDesign = function (absolutePath, id, text) {
var bpmnDesign = new BpmnDesign();
bpmnDesign.showPage({}, {
data: {
absolutePath: absolutePath,
id: id,
text: text
}
});
};
Workbench.prototype.showLayoutDesign = function (layoutCode, layoutName) {
var id = layoutCode !== null && layoutCode !== void 0 ? layoutCode : _$2.uniqueId('new_layout');
var layoutDesign = new WidgetDesign$1(layoutCode, layoutName);
layoutDesign.showPage({
id: id,
path: id,
}, {
data: {}
});
};
Workbench.prototype.tabchange = function (tabPanel, newCard, oldCard, eOpts) {
var _a;
// this.activeModulePage = newCard.yvanScope
handles$1.viewoutlinetree.moduleId = newCard.yvanScope.moduleId;
handles$1.property.moduleId = newCard.yvanScope.moduleId;
// handles.dbTree.moduleId = newCard.yvanScope.moduleId
// handles.dictTree.moduleId = newCard.yvanScope.moduleId
// handles.fileTree.moduleId = newCard.yvanScope.moduleId
// handles.statusbar.moduleId = newCard.yvanScope.moduleId
eventBus.publish(EventType.MainTabChange, {
moduleId: newCard.yvanScope.moduleId,
oldModuleId: (_a = oldCard === null || oldCard === void 0 ? void 0 : oldCard.yvanScope) === null || _a === void 0 ? void 0 : _a.moduleId,
from: this.name
});
};
Workbench.prototype.onUndo = function () {
var _a;
(_a = this.activeModulePage) === null || _a === void 0 ? void 0 : _a.moduleEventBus.publish(EventType.Undo, {});
};
Workbench.prototype.onRedo = function () {
var _a;
(_a = this.activeModulePage) === null || _a === void 0 ? void 0 : _a.moduleEventBus.publish(EventType.Redo, {});
};
Workbench.prototype.onCut = function (a, b, c, d) {
var _a;
(_a = this.activeModulePage) === null || _a === void 0 ? void 0 : _a.moduleEventBus.publish(EventType.Cut, {});
};
Workbench.prototype.onCopy = function (a, b, c, d) {
var _a;
(_a = this.activeModulePage) === null || _a === void 0 ? void 0 : _a.moduleEventBus.publish(EventType.Copy, {});
};
Workbench.prototype.onPaste = function (a, b, c, d) {
var _a;
(_a = this.activeModulePage) === null || _a === void 0 ? void 0 : _a.moduleEventBus.publish(EventType.Paste, {});
};
Workbench.prototype.onSelectAll = function () {
var _a;
(_a = this.activeModulePage) === null || _a === void 0 ? void 0 : _a.moduleEventBus.publish(EventType.SelectAll, {});
};
return Workbench;
}(Scope));
(function (FuncDomain) {
FuncDomain["SCOPE"] = "scope";
FuncDomain["SYSTEM"] = "system";
})(exports.FuncDomain || (exports.FuncDomain = {}));
(function (BizMode) {
//mode : 1, '仅查询' 2, '表单+表格编辑' 3, '仅表单编辑' 4, '仅表格编辑'
BizMode[BizMode["query"] = 1] = "query";
BizMode[BizMode["formAndGridEdit"] = 2] = "formAndGridEdit";
BizMode[BizMode["formEditOnly"] = 3] = "formEditOnly";
BizMode[BizMode["gridEditOnly"] = 4] = "gridEditOnly";
})(exports.BizMode || (exports.BizMode = {}));
(function (BizFormat) {
// "format" : 1, button 2 progres 3 date 4 datetime 5 percentage
BizFormat[BizFormat["button"] = 1] = "button";
BizFormat[BizFormat["progress"] = 2] = "progress";
BizFormat[BizFormat["date"] = 3] = "date";
BizFormat[BizFormat["datetime"] = 4] = "datetime";
BizFormat[BizFormat["percentage"] = 5] = "percentage";
})(exports.BizFormat || (exports.BizFormat = {}));
(function (BizUnique) {
// "unique" : 1主键(全局唯一) 2仓库唯一 3货主唯一 4项目唯一 5单据唯一 6仓库+货主+项目唯一
BizUnique[BizUnique["u_a"] = 1] = "u_a";
BizUnique[BizUnique["u_wh"] = 2] = "u_wh";
BizUnique[BizUnique["u_ow"] = 3] = "u_ow";
BizUnique[BizUnique["u_pj"] = 4] = "u_pj";
BizUnique[BizUnique["u_od"] = 5] = "u_od";
BizUnique[BizUnique["u_wh_ow_pj"] = 6] = "u_wh_ow_pj";
})(exports.BizUnique || (exports.BizUnique = {}));
var ScopeEngine = /** @class */ (function () {
function ScopeEngine() {
}
ScopeEngine.getBizFile = function (director) {
return new Promise(function (resolve, reject) {
debugger;
});
};
ScopeEngine.buildScopeFromBillFile = function (billFile) {
return new Promise(function (resolve, reject) {
var requireArr = [];
var requireKeyArr = [];
_$2.forOwn(billFile.domains, function (v, k) {
requireArr.push(v.domain);
requireKeyArr.push(k);
if (v.layout) {
requireArr.push(v.layout);
requireKeyArr.push(k + "_layout");
}
});
requireArr.push(billFile.layout);
requireKeyArr.push("layout");
requireArr.push(billFile.converter);
requireKeyArr.push("converter");
// @ts-ignore
require(requireArr, function () {
var requireReArr = [];
for (var _i = 0; _i < arguments.length; _i++) {
requireReArr[_i] = arguments[_i];
}
if (requireReArr.length <= 0) {
reject(new Error("没有加载到相关的文件!"));
}
var domains = {};
for (var i = 0; i < requireReArr.length - 2; i++) {
if (requireKeyArr[i].endsWith("_layout")) {
var key_d = requireKeyArr[i].substr(0, requireKeyArr[i].indexOf("_layout"));
domains[key_d].layout = requireReArr[i].default;
}
else {
domains[requireKeyArr[i]] = requireReArr[i].default;
domains[requireKeyArr[i]].type = billFile.domains[requireKeyArr[i]].type;
domains[requireKeyArr[i]].mode = billFile.domains[requireKeyArr[i]].mode;
}
}
var bizFile = {
bill: billFile,
domains: domains,
layout: requireReArr[requireReArr.length - 2].default,
converter: requireReArr[requireReArr.length - 1].default,
};
var scope = ScopeEngine.buildScopeFromBizFile(bizFile);
scope.billSetting = bizFile;
resolve(scope);
});
});
};
ScopeEngine.buildScopeFromPath = function (path) {
return new Promise(function (resolve, reject) {
// @ts-ignore
require([path], function (bill) {
bill = bill.default;
ScopeEngine.buildScopeFromBillFile(bill).then(function (scope) {
resolve(scope);
}).catch(function (e) {
reject(e);
});
});
});
};
ScopeEngine.buildScopeFromBizFile = function (bizFile) {
var controller = {};
var vjson = {
layout: 'fit',
title: bizFile.bill.name,
items: []
};
var model = {};
if (bizFile.layout.layout === "fit") {
vjson.items = bizFile.layout.items;
}
else if (bizFile.layout.layout === "border") {
vjson.items = [bizFile.layout];
}
var domainsVjson = {};
_$2.forOwn(bizFile.domains, function (v, k) {
var domainVjson = null;
var buttons = bizFile.domains[k].buttons;
if (bizFile.bill.domains[k].mode === "form") {
domainVjson = ScopeEngine.buildForm(controller, model, bizFile, k);
if (Array.isArray(buttons) && buttons.length > 0) {
if (bizFile.bill.domains[k].type === "header") {
vjson.tbar = {
xtype: 'toolbar',
items: ScopeEngine.buildButton(controller, buttons)
};
}
else {
domainVjson.items.push({
xtype: "cols",
items: ScopeEngine.buildButton(controller, buttons)
});
}
}
}
else if (bizFile.bill.domains[k].mode === "table") {
domainVjson = ScopeEngine.buildGrid(controller, model, bizFile, k);
if (Array.isArray(buttons) && buttons.length > 0) {
if (bizFile.bill.domains[k].type === "header") {
vjson.tbar = {
xtype: 'toolbar',
items: ScopeEngine.buildButton(controller, buttons)
};
}
else {
domainVjson.tbar = {
xtype: 'toolbar',
items: ScopeEngine.buildButton(controller, buttons)
};
}
}
}
if (domainVjson) {
domainsVjson[k] = domainVjson;
}
});
ScopeEngine.deepTravVJsonReplaceDomain(vjson, domainsVjson);
var scope = new Scope({ model: model, vjson: vjson });
scope['bill_define'] = bizFile;
_$2.merge(scope, controller);
console.log('bill_define', vjson, scope, scope['bill_define']);
return scope;
};
ScopeEngine.buildForm = function (controller, model, bizFile, domainKey) {
var fieldGroups = {};
for (var i = 0; i < bizFile.domains[domainKey].fields.length; i++) {
var field = bizFile.domains[domainKey].fields[i];
var item = { sort: field.form_sort };
item.xtype = field.xtype;
item.fieldLabel = field.column_desc;
item.bind = {
value: "{" + domainKey + "." + field.column_name + "}",
};
_$2.set(model, "data." + domainKey + "." + field.column_name, null);
// if (field.disabled !== "true" && field.disabled !== "false") {
// item.bind.disabled = eval(field.disabled)
// } else {
// item.disabled = (field.disabled === "true")
// }
// if (field.readonly !== "true" && field.readonly !== "false") {
// item.bind.disabled = eval(field.readonly)
// } else {
// item.readonly = (field.readonly === "true")
// }
// if (field.required !== "true" && field.required !== "false") {
// item.bind.required = eval(field.required)
// } else {
// item.required = (field.required === "true")
// }
// if (field.hide !== "true" && field.hide !== "false") {
// item.bind.hidden = eval(field.hide)
// } else {
// item.hidden = (field.hide === "true")
// }
// item.flex = field.
if (field.dict) {
item.fix = eval(field.dict);
}
// _.set(formModel, "", "")
item.field = field;
if (field.form_group) {
if (!fieldGroups.hasOwnProperty(field.form_group)) {
fieldGroups[field.form_group] = [item];
}
else {
fieldGroups[field.form_group].push(item);
}
}
}
var formVjson = {
xtype: "form",
title: bizFile.domains[domainKey].name,
items: []
};
_$2.forOwn(fieldGroups, function (fieldGroup, k) {
var items = ScopeEngine.buildFieldSet(fieldGroup);
if (items) {
var fieldsetVjson = {
xtype: "fieldset",
title: k,
items: items
};
formVjson.items.push(fieldsetVjson);
}
});
return formVjson;
};
ScopeEngine.buildGrid = function (controller, model, bizFile, domainKey) {
// const vjson = { xtype: "grid", items: []}
var gridVjson = {
xtype: "yvgrid",
columns: [],
split: true,
reference: domainKey,
listeners: {
itemdblclick: function () {
},
},
};
for (var i = 0; i < bizFile.domains[domainKey].fields.length; i++) {
var field = bizFile.domains[domainKey].fields[i];
gridVjson.columns.push({
dataIndex: field.column_name,
header: field.column_desc,
});
}
return gridVjson;
};
ScopeEngine.buildFieldSet = function (fieldGroup) {
var colGroups = [{
xtype: "cols",
items: []
}];
var colGroup = colGroups[0];
_$2.sortBy(fieldGroup, function (item) { return item.sort; });
for (var i = 0; i < fieldGroup.length; i++) {
var field = fieldGroup[i];
if (field.field.form_newline === "true") {
if (colGroup.items.length > 0) {
colGroup = {
xtype: "cols",
items: [field]
};
colGroups.push(colGroup);
}
}
else {
colGroup.items.push(field);
}
delete field.field;
}
return colGroups;
};
ScopeEngine.buildButton = function (controller, buttons) {
var buttonsVjson = [];
var _loop_1 = function (i) {
var item = buttons[i];
var button = {
xtype: "button",
text: item.btn_name,
iconCls: item.icon
};
if (item.hidden === "true" || item.hidden === "false") {
button.hidden = (item.hidden === "true");
}
if (item.listeners) {
var listeners_1 = {};
_$2.forOwn(item.listeners, function (v, k) {
if (v.startsWith(exports.FuncDomain.SCOPE + ".") || v.startsWith(exports.FuncDomain.SYSTEM + ".")) {
listeners_1[k] = v;
}
else {
try {
listeners_1[k] = eval(v);
}
catch (e) {
throw e;
}
}
});
button.listeners = listeners_1;
}
buttonsVjson.push(button);
};
for (var i = 0; i < buttons.length; i++) {
_loop_1(i);
}
return buttonsVjson;
};
ScopeEngine.buildListeners = function (controller, item) {
if (!item.hasOwnProperty("listeners")) {
return;
}
_$2.forOwn(item.listeners, function (v, k) {
if (v && typeof v === "string") {
if (v.indexOf(".") > -1) {
var strArr = v.split(".");
if (strArr.length != 2) {
console.error(item.listeners, "语法解析错误,请检查!");
}
var _a = __read(strArr, 2), funcDomain = _a[0], funcName = _a[1];
switch (funcDomain) {
case exports.FuncDomain.SCOPE:
controller[k] = findCustFunc(item, k);
break;
case exports.FuncDomain.SYSTEM:
break;
default:
throw new Error("错误的函数域定义");
}
}
else {
var func = eval(v);
if (typeof func === 'function') {
controller[k] = func;
}
throw new Error("解析自定义函数出错");
}
}
});
var findCustFunc = function (item, funcName) {
if (!item.hasOwnProperty("funcs") || !item[funcName]) {
throw new Error("没有找到相关的函数定义");
}
var func = eval(item[funcName]);
if (typeof func === 'function') {
return func;
}
throw new Error("解析自定义函数出错");
};
};
/**
* 只检索 items 的模式,深度遍历 vjson
*/
ScopeEngine.deepTravVJsonReplaceDomain = function (vjson, domainsVjson) {
if (Array.isArray(vjson)) {
for (var i = 0; i < vjson.length; i++) {
ScopeEngine.deepTravVJsonReplaceDomain(vjson[i], domainsVjson);
}
}
else {
_$2.forOwn(vjson, function (v, k) {
if (k !== "domain") {
if (Array.isArray(v) || Object.prototype.toString.call(v) === "[object Object]") {
ScopeEngine.deepTravVJsonReplaceDomain(v, domainsVjson);
}
}
else {
delete vjson.domain;
_$2.merge(vjson, domainsVjson[v]);
}
});
}
};
return ScopeEngine;
}());
function initComponent () {
var ct = Ext.Component.prototype.constructor;
Ext.Component.override({
constructor: function (config) {
var _a, _b;
if (!isDesignMode(this, config)) {
var me_1 = this;
// 任意组件 Ext.Component 构造时调用的方法, 可以用来在渲染之前加工处理 VJSON
_$2.each(baseConfigProcessList, function (process) {
process.call(me_1, me_1, config);
});
}
if (config) {
if (!config.i18nPath && ((_a = config.$initParent) === null || _a === void 0 ? void 0 : _a.i18nPath)) {
config.i18nPath = config.$initParent.i18nPath;
}
if ((_b = config.$initParent) === null || _b === void 0 ? void 0 : _b.setTitle) {
var setTitle_1 = config.$initParent.setTitle;
var handel_1 = config.$initParent;
config.$initParent.setTitle = function (title) {
var t = { title: title };
var WMSTranslate = window["WMSTranslate"];
if (WMSTranslate) {
if (typeof window['viewTranslate'] === 'function') {
window['viewTranslate'](t, title, "title");
}
}
setTitle_1.call(handel_1, t.title);
}.bind(config.$initParent);
}
var WMSTranslate = window["WMSTranslate"];
if (WMSTranslate) {
if (typeof window['viewTranslate'] === 'function') {
window['viewTranslate'](config, config.text, "text");
window['viewTranslate'](config, config.title, "title");
window['viewTranslate'](config, config.header, "header");
window['viewTranslate'](config, config.fieldLabel, "fieldLabel");
window['viewTranslate'](config, config.emptyText, "emptyText");
}
}
}
ct.call(this, config);
}
});
var _initComponent = Ext.picker.Date.prototype.initComponent;
Ext.picker.Date.override({
initComponent: function () {
var me = this;
me.defaultValue = Ext.isDate(me.defaultValue) ? me.defaultValue : syncDate(new Date());
_initComponent.call(me);
},
selectToday: function () {
var me = this, btn = me.todayBtn, handler = me.handler;
if (btn && !btn.disabled) {
me.setValue(Ext.Date.clearTime(syncDate(new Date())));
me.fireEvent('select', me, me.value);
if (handler) {
Ext.callback(handler, me.scope, [me, me.value], null, me, me);
}
me.onSelect();
}
return me;
},
});
}
function initMainTab () {
Ext.define('Yvan.MainTab', {
extend: 'Ext.tab.Panel',
xtype: 'maintab',
plugins: Ext.create('Ext.ux.TabCloseMenu', {
closeTabText: '关闭',
closeOthersTabsText: '关闭其他',
closeAllTabsText: '关闭所有'
}),
constructor: function (config) {
var me = this;
var newConfig = _$2.defaultsDeep({
// 强制属性
}, config);
this.superclass.constructor.call(me, newConfig);
},
initComponent: function () {
var me = this;
this.on({
tabchange: function (tabPanel, newCard, oldCard, eOpts) {
_$2.defer(function () {
me.changeHash(newCard.id);
window['cp'] = newCard.yvanScope;
});
$$2(window).trigger('tabChange', {
tabPanel: tabPanel, newCard: newCard, oldCard: oldCard, eOpts: eOpts
});
},
afterrender: function () {
_$2.defer(function () {
me.tryRestoryPage();
});
}
});
this.superclass.initComponent.call(me);
},
tryRestoryPage: function () {
var me = this;
var hash = '' + window.location.hash;
if (hash && hash.indexOf('page=') > 0) {
if (hash.startsWith('#')) {
hash = hash.substr(1);
}
if (hash) {
var page = Qs.parse(hash).page;
if (page) {
// this.openScope(page)
me.fireEvent('restorypage', page);
}
}
}
},
changeHash: function (id) {
window.location.hash = Qs.stringify({ page: id });
},
/**
* 添加一个业务模块实例到选项卡
* @param scopeInstance 业务对象实例
* @param config ExtJS配置对象
* @param panelInitCallback panel初始化之后会调用函数进行构造前的加工
*/
addScope: function (scopeInstance, config, panelInitCallback) {
scopeInstance.topScope = scopeInstance;
var me = this;
if (config.path) {
for (var i = 0; i < this.items.items.length; i++) {
// 找到当前 tabs 里有没有已经打开过
var tab = this.items.items[i];
if (_$2.isEqual(tab.path, config.path)) {
// 激活
this.setActiveTab(tab);
return tab;
}
}
}
var newPanel = new Ext.panel.Panel(__assign({ closable: true }, config));
if (typeof panelInitCallback === 'function') {
panelInitCallback(newPanel);
}
// 添加业务模块
var newTab = this.add(newPanel);
this.setActiveTab(newTab);
newTab.on({
destroy: function (sender) {
me.changeHash('');
delete window['cp'];
}
});
return newTab;
}
});
}
/**
* 构建所有组件的公共属性
* @param config 原始config
* @param dragType 组件模式
* 不填,代表不能在设计时被拖拽
* row-container 是一个rows容器
* col-container 是一个cols容器
* col-item cols中的一个格子(非容器),比如 textfield / combofield 等等
* row-item rows中的一行,比如 tree / grid / panel 等等
*/
function baseConfig(config, dragType) {
// if (isDesignMode(config, undefined) && dragType) {
if (typeof config === 'object') {
var cc = '';
switch (dragType) {
case "cols-container":
cc = 'design_cols_container';
break;
case "col-item":
cc = 'design_col_item';
break;
case "rows-container":
cc = 'design_rows_container';
break;
case "row-item":
cc = 'design_row_item';
break;
}
if (typeof config.cls === 'string') {
_$2.extend(config, {
cls: [config.cls, 'yvan_design', cc]
});
}
else if (_$2.isArray(config.cls)) {
_$2.extend(config, {
cls: __spread(config.cls, ['yvan_design', cc])
});
}
else {
_$2.extend(config, {
cls: ['yvan_design', cc]
});
}
}
return config;
}
function initPanel () {
/**
*
*/
var ct = Ext.panel.Panel.prototype.constructor;
Ext.panel.Panel.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({}, config, baseConfig(config, "rows-container"), panel);
ct.call(this, newConfig);
}
});
var ss = Ext.form.FieldContainer.prototype;
Ext.form.FieldContainer.override({
config: __assign({}, fieldContainer)
});
}
function initGridColumn () {
var ct = Ext.grid.column.Column.prototype.constructor;
Ext.grid.column.Column.override({
constructor: function (config) {
var scope = lookupScope(config.$initParent.$initParent);
var newConfig = _$2.defaults({}, config, column);
if (typeof newConfig.summaryRenderer === 'string') {
newConfig.summaryRenderer = lookupFn(scope, config.summaryRenderer);
if (typeof newConfig.summaryRenderer === 'function') {
newConfig.summaryRenderer = newConfig.summaryRenderer.bind(scope);
}
}
if (config.formatter === 'datetime') {
newConfig.fix = ['system.formatDate()'];
delete newConfig.formatter;
}
// 在 grid.constructor 已经转换过了
// if (typeof newConfig.renderer === 'string') {
// newConfig.renderer = lookupFn(scope, config.renderer)
// if (typeof newConfig.renderer === 'function') {
// newConfig.renderer = newConfig.renderer.bind(scope)
// }
// }
ct.call(this, newConfig);
}
});
var ctAction = Ext.grid.column.Action.prototype.constructor;
Ext.grid.column.Action.override({
constructor: function (config) {
var scope = lookupScope(config.$initParent.$initParent);
_$2.forEach(config.items, function (item) {
if (typeof item.handler === 'string') {
item.handler = lookupFn(scope, item.handler);
if (typeof item.handler === 'function') {
item.handler = item.handler.bind(scope);
}
}
});
ctAction.call(this, config);
}
});
var ck = Ext.grid.column.Check.prototype.constructor;
Ext.grid.column.Check.override({
constructor: function (config) {
_$2.set(config, 'listeners.checkchange', function (sender, rowIndex, checked, record, e, eOpts) {
var grid = sender.view.grid.ownerGrid;
var column = grid.getColumns()[sender.fullColumnIndex];
var context = {
event: e,
column: column,
field: sender.dataIndex,
value: checked,
record: record,
rowIdx: rowIndex
};
grid.fireEvent('editfinish', grid, sender, context, eOpts);
});
ck.call(this, config);
}
});
// 227573
// const {onTitleElClick} = Ext.grid.column.Column.prototype
// Ext.define('Yvan.ColumnOverride', {
// override: 'Ext.grid.column.Column',
//
// config: {
// enableSortOnClick: false,
// },
//
// // /**@Overrides*/
// onTitleElClick: function (e, t, sortOnClick) {
// // return this.callParent([e, t, this.enableSortOnClick && sortOnClick]);
// if (!$(e.target).is('.x-column-header-trigger')) {
// // 不是点击菜单的情况下,让列自适应宽度
// this.autoSize()
// }
// return onTitleElClick.call(this, e, t, false)
// }
// });
}
var SIMPLE_RE = /^(?:\{(?:(\d+)|([a-z_][\w\.]*))\})$/i;
/**
* 判断目标字符串与关键字是否重叠
* @param target 目标字符串
* @param keyword 搜索关键字
*/
function pinyinMatch(target, keyword) {
if (typeof target != 'string' || typeof keyword != 'string') {
return false;
}
if (!keyword || !target) {
return false;
}
var pyzh = _$2.toLower(window['getFirstPinyin2'](target));
keyword = _$2.toLower(keyword);
var pos1 = _$2.toLower(target).indexOf(keyword);
if (pos1 >= 0) {
return true;
}
var len = _$2.intersection(keyword.split('')).length;
if (_$2.intersection(pyzh.split(''), keyword.split('')).length === len) {
return true;
}
return false;
}
/**
* 对某个表达式进行求值
* a:{query.a},b:{query.b} -> a:aValue,b:bValue
*
* @example
* calcExpress(cc.viewModel.data, "WH_ID:{query.WH_ID},C:{theGrid.selection.data.WH_ID}")
* 计算出来的值是: "WH_ID:queryWhId,C:JH000000001"
*
* @param data 数据环境对象
* @param express 表达式对象
*/
function calcExpress(data, express) {
var result = express;
if (SIMPLE_RE.test(express)) {
// '{foo}' 简单表达式
var path = express.substring(1, express.length - 1);
var ret = _$2.get(data, path);
return (ret === null || ret === void 0 ? void 0 : ret.isModel) ? ret.data : ret;
}
while (true) {
var mlist = result.match(/{(.*?)}/);
if (!mlist) {
break;
}
var pathC = mlist[0]; // {query.a}
var path = mlist[1]; // query.a
var value = _$2.get(data, path);
result = result.replaceAll(pathC, value || '');
}
return result;
}
/**
* 对个对象进行表达式求值,不用回调
* @example
* calcObjectFlat({query:{a:'aValue',b1:'b1Value',b2:'b2Value',d1:1,d2:2}}, { a:'{query.a}', b:{b1:'{query.b1}', b2:'{query.b2}'},c:'aa',d:['{query.d1}','{query.d2}'] })
*
* {
* a: '{query.a}',
* b: {
* b1: '{query.b1}',
* b2: '{query.b2}',
* },
* c: 'aa',
* d: [
* '{query.d1}',
* '{query.d2}'
* ]
* }
*
* 计算结果为
* {
* a: 'aValue',
* b: {
* b1: 'b1Value',
* b2: 'b2Value'
* },
* c: 'aa'
* d: [
* '1',
* '2'
* ]
* }
*
* @param data
* @param paramObject
*/
function calcObjectFlat(data, paramObject) {
var result = _$2.cloneDeep(paramObject);
if (typeof paramObject === 'string') {
return calcExpress(data, paramObject);
}
var trav = function (param) {
_$2.forOwn(param, function (value, key) {
if (_$2.isPlainObject(value)) {
// 深度递归,对子对象进行求解
trav(value);
}
else if (_$2.isString(value)) {
// 字符串直接用 calcExpress 表达式求解
param[key] = calcExpress(data, param[key]);
}
else if (_$2.isArray(value)) {
// 数组求解
_$2.each(value, function (v, idx) {
value[idx] = calcExpress(data, v);
});
}
});
};
trav(result);
return result;
}
/**
* 合併 data 到當前的 ViewModel 對象
*/
function mergeViewModel(viewModel, propertyName, data, isFlat) {
var newRow = {};
if (isFlat == false) {
newRow = data;
}
else {
flatObject(newRow, '', data);
}
if (!propertyName) {
_$2.forOwn(newRow, function (value, key) {
viewModel.set(key, value);
});
}
else {
_$2.forOwn(newRow, function (value, key) {
viewModel.set(propertyName + "." + key, value);
});
}
}
/**
* 转换内联结构的行,到平面结构
* company: { name:'公司1', id:'编号1' } => { company_id:'编号1', company_name:'公司1' }
*
* @param array
* @param flatOption
* @return {[]}
*/
function flatRow(array) {
var ret = [];
_$2.forEach(array, function (row) {
var newRow = {};
flatObject(newRow, '', row);
ret.push(newRow);
});
return ret;
}
function flatObject(parentObj, parentProp, obj) {
_$2.forOwn(obj, function (value, key) {
var fullKey = parentProp ? parentProp + '_' + key : key;
if (_$2.isArray(value)) {
parentObj[fullKey] = _$2.map(value, function (row) {
var newRow = {};
flatObject(newRow, '', row);
return newRow;
});
}
else {
if (typeof value === 'object') {
flatObject(parentObj, fullKey, value);
}
else {
parentObj[fullKey] = value;
}
}
});
}
/**
* 替换内部结构中,所有 N/A
*/
function replaceNA(obj) {
if (obj === 'N/A') {
return '';
}
if (_$2.isArray(obj)) {
_$2.forEach(obj, function (value, idx) {
if (value === 'N/A') {
obj[idx] = '';
}
else {
if (typeof value === "string" && /^-?\d*\.?\d+$/.test(value)) {
obj[idx] = parseFloat(value) + "";
}
else {
replaceNA(value);
}
}
});
}
else if (_$2.isPlainObject(obj)) {
_$2.forOwn(obj, function (value, key) {
if (value === 'N/A') {
obj[key] = '';
}
else {
if (typeof value === "string" && /^-?\d*\.?\d+$/.test(value)) {
obj[key] = parseFloat(value) + "";
}
else {
replaceNA(value);
}
}
});
}
}
function deepTravJson(obj, resolver) {
if (_$2.isArray(obj)) {
_$2.forEach(obj, function (value, idx) {
if (typeof value === 'string') {
resolver(obj, value, idx);
}
else {
deepTravJson(value, resolver);
}
});
}
else if (_$2.isPlainObject(obj)) {
_$2.forOwn(obj, function (value, key) {
if (typeof value === 'string') {
resolver(obj, value, key);
}
else {
deepTravJson(value, resolver);
}
});
}
}
/**
* 根据表达式进入写值
* express="{query.a}" 写值就是 viewModel.set('query.a', value)
* express="test-{query.a}" 写值就会失败
*
* @example
* tryWriteByExpress(cc.viewModel, "{query.WH_ID}", "111")
* 写值成功
*
* tryWriteByExpress(cc.viewModel, "test-{query.WH_ID}", "111")
* 写值失败
*
* @param viewModel VM对象
* @param express 表达式对象
* @param value 目标值
*/
function tryWriteByExpress(viewModel, express, value) {
if (SIMPLE_RE.test(express)) {
// '{foo}' 简单表达式
express = express.substring(1, express.length - 1);
viewModel.set(express, value);
}
}
/**
* 尝试根据含表达式的对象回写, calcObjectFlat 的逆向方法
* @example
* tryWriteObject({ a:'{query.a}', b:{b1:'{query.b1}', b2:'{query.b2}'},c:'aa',d:['{query.d1}','{query.d2}']}, {a:'aValue', b:{b1:'b1Value', b2:'b2Value'}, c:'aa', d:[1,2]})
*
* expressObject:
* {
* a: '{query.a}',
* b: {
* b1: '{query.b1}',
* b2: '{query.b2}',
* },
* c: 'aa',
* d: [
* '{query.a}',
* '{query.b2}'
* ]
* }
*
* valueObject:
* {
* a: 'aValue',
* b: {
* b1: 'b1Value',
* b2: 'b2Value'
* },
* c: 'aa'
* c: [
* 'aValue',
* 'b2Value'
* ]
* }
*
* 系统会尝试回写
* viewModel.set('query.a', 'aValue')
* viewModel.set('query.b1', 'b1Value')
* viewModel.set('query.b2', 'b2Value')
*
* @param expressObject 含表达式的对象
* @param valueObject 表达式计算完成之后的结果对象
* @param writeFn 写入的方法 (path, value)=>void
*/
function tryWriteObject(expressObject, valueObject, writeFn) {
var trav = function (pathPrefix) {
var parent = expressObject;
if (_$2.size(pathPrefix) > 1) {
parent = _$2.get(parent, pathPrefix.substring(1));
}
_$2.forOwn(parent, function (value, key) {
if (_$2.isPlainObject(value)) {
// 深度递归,对子对象进行求解
trav(pathPrefix + "." + key);
}
else if (_$2.isString(value)) {
// 字符串直接用 calcExpress 表达式求解
if (SIMPLE_RE.test(value)) {
// If we have '{foo}' alone it is a literal 简单表达式
var targetPath = value.substring(1, value.length - 1);
var targetValue = _$2.get(valueObject, (pathPrefix + "." + key).substr(1));
if (!writeFn) {
console.log("viewModel.set('" + targetPath + "', '" + targetValue + "')");
}
else {
writeFn(targetPath, targetValue);
}
}
}
else if (_$2.isArray(value)) {
_$2.each(value, function (v, idx) {
if (SIMPLE_RE.test(v)) {
var targetPath = (pathPrefix + "." + key).substr(1) + "[" + idx + "]";
var targetValue = _$2.get(valueObject, (pathPrefix + "." + key).substr(1) + "[" + idx + "]");
if (!writeFn) {
console.log("viewModel.set('" + targetPath + "', '" + targetValue + "')");
}
else {
writeFn(targetPath, targetValue);
}
}
});
}
});
};
trav("");
}
/**
* 尝试去掉变量两边括号
* {a} => a
* a => a
*/
function tryVarSimple(value) {
if (SIMPLE_RE.test(value)) {
// If we have '{foo}' alone it is a literal 简单表达式
return value.substring(1, value.length - 1);
}
return value;
}
/**
* 对多个表达式进行求值. 异步回调的方式返回
* {
* a: 1,
* b: '{someBind}',
* c: ['a', 'b', 'c'],
* d: ['a', 'b', '{someBind}'],
* e: {
* y: 1,
* z: 2
* },
* f: {
* y: 1,
* z: '{someBind}'
* }
* }
*
* // Will produce
* {
* b: value,
* d: ['a', 'b', value],
* f: {
* y: 1,
* z: value
* }
* }
* @param viewModel scope.viewModel对象
* @param paramObject 求值对象
*/
function calcObject(viewModel, paramObject) {
// new Ext.app.bind.Multi({a:'1',b:'ddd{query.WH_ID}'},currentScope.viewModel,function(v){console.log(v)},currentScope, {single: true})
return new Promise(function (resolve) {
var schedule = new Ext.app.bind.Multi(paramObject, viewModel, function (ret) {
schedule.destroy();
// 从 Ext.data.Model 对象转换为 js-object 对象
ret = toPlainObject(ret);
resolve(ret);
}, viewModel, { single: true });
});
}
/**
* 用于任意组件 Ext.Component 构造时,获取当前组件对应的表格(如果不是 grid.columns 对象就会返回 undefined)
* @param config 组件构造函数传入的 config 配置文件
*/
function getParentGrid(config) {
var _a;
return (_a = config.$initParent) === null || _a === void 0 ? void 0 : _a.grid;
}
/**
* 解析
* {
* condition: "{skuId}",
* errorMsg: "无法编辑",
* notice: 'msg'
* }
*/
function tryEnable(data, enableSetting) {
if (!enableSetting) {
// 没有这一段配置,可以编辑
return true;
}
var condition = enableSetting.condition, errorMsg = enableSetting.errorMsg, notice = enableSetting.notice;
if (!evalFunction(data, condition)) {
// 没有达成 condition 条件
// 计算 msg 消息内容
var msgContent = calcExpress(data, errorMsg);
if (msgContent) {
if (!notice || notice === 'msg') {
// 进行提示
msg$1(msgContent);
}
}
return false;
}
return true;
}
/**
* 动态的为 combo 或 columns.combo 设置下拉框的值
* @param sender 目标对象
* @param config 目标对象的配置(在构造函数之前也可以)
* @param getDictFn 获取字典的方法
* @param bizKey 传入字典的参数
* @param multiValueSeparator 多个字典值的分割符号
*/
function setComboStore(sender, config, getDictFn, bizKey, multiValueSeparator) {
if (multiValueSeparator === void 0) { multiValueSeparator = ""; }
// sender 和 config为空的时候获取值、
if (_$2.isArray(getDictFn)) {
// 如果 getDictFn 是直接给定的值,就造一个异步回调的方法
var realArray_1 = getDictFn;
getDictFn = function () {
return realArray_1;
};
}
if (!sender) {
return new Promise(function (resolve, reject) {
getDictFn(bizKey, function (r) {
resolve({ config: config, r: r });
});
});
}
if (sender.xtype === 'combotree') {
getDictFn(bizKey, function (r) {
if (sender.store) {
// 异步回传
sender.setStore(new Ext.data.TreeStore({ root: r }));
}
else {
// 同步回传
config.store = new Ext.data.TreeStore({ root: r });
}
});
return;
}
else if (sender.$className === 'Ext.form.field.ComboBox' || sender.$className === 'Ext.form.field.Tag') {
getDictFn(bizKey, function (r) {
var _a, _b;
if (sender.store) {
// 异步回传
sender.setStore(new Ext.data.Store(r));
// 这里有个bug, 异步回传完毕之后, 需要强制刷新一下
// 否则在 forceSelection 的模式下。displayField 不会强制做变更
var realValue = (_b = (_a = sender.bind) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.getValue();
if (typeof realValue !== 'undefined') {
sender.setValue(realValue);
}
}
else {
// 同步回传
config.store = new Ext.data.Store(r);
}
});
return;
}
else if (sender.xtype === 'gridcolumn') {
var grid = getParentGrid(config);
var editor_1 = config.editor, renderer = config.renderer;
getDictFn(bizKey, function (r) {
if (sender.store) {
// 已经渲染出来了, 用方法进行修改
var editor_2 = sender.getEditor();
if (editor_2 && editor_2.xtype === 'combo') {
var valueField_1 = r.field[0];
var displayField_1 = r.field[1];
editor_2.valueField = valueField_1;
editor_2.setDisplayField(displayField_1);
editor_2.setStore(new Ext.data.Store(r));
}
if (!sender.disableListFilter) {
sender.setFilter({
type: 'list',
options: _$2.map(r.data, function (r) { return ({
id: '' + r.id,
text: r.text,
}); })
});
}
}
else {
// 没有渲染之前,修改 config 即可
if (editor_1 && editor_1.xtype === 'combo') {
// 带编辑模式
editor_1.store = new Ext.data.Store(r);
}
if (!sender.disableListFilter) {
config.filter = {
type: 'list',
options: _$2.map(r.data, function (r) { return ({
id: '' + r.id,
text: r.text,
}); })
};
}
}
// 当 metaData === true 表示反向取字典 (根据字典显示值获取id值)
var renderer = function (value, metaData) {
if (metaData === void 0) { metaData = false; }
if (!value && value != 0) {
return '';
}
var valueField = r.field[metaData === true ? 1 : 0];
var displayField = r.field[metaData === true ? 0 : 1];
var separator = multiValueSeparator;
if (separator) {
var arr = value.split(separator);
var displayValue_1 = "";
var _loop_1 = function (i) {
var itv = arr[i];
if (i > 0) {
displayValue_1 += separator;
}
_$2.each(r.data, function (row) {
// 从 valueField 找到要显示的 displayField
if (row[valueField] == itv) {
displayValue_1 += row[displayField];
return false;
}
else {
if (i >= r.data.length - 1) {
displayValue_1 += itv;
}
}
});
};
for (var i = 0; i < arr.length; i++) {
_loop_1(i);
}
return displayValue_1;
}
_$2.each(r.data, function (row) {
// 从 valueField 找到要显示的 displayField
if (row[valueField] == value) {
value = row[displayField];
return false;
}
});
return value;
};
var dictForExcel = {};
var valueField = r.field[0];
var displayField = r.field[1];
_$2.each(r.data, function (row) {
// 从 valueField 找到要显示的 displayField
var key = row[valueField];
if (key != '' && typeof key != "undefined" && key != null) {
dictForExcel[key] = row[displayField];
}
});
if (sender.rendered) {
// 已经渲染出来了, 对列进行渲染
sender.renderer = renderer;
sender.dictForExcel = dictForExcel;
sender.getView().refresh();
}
else {
sender.renderer = renderer;
sender.dictForExcel = dictForExcel;
config.renderer = renderer;
config.dictForExcel = dictForExcel;
}
});
return;
}
throw new TypeError("无法识别的组件类型");
}
/**
* 调用服务器 Ajax
*/
function invokeServer$1(url) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
// @ts-ignore
return ajax.func({
url: url,
method: 'invoke',
args: args
});
}
function clearViewModelValues(viewModel, propertyName) {
if (!propertyName) {
var dd_1 = viewModel.getData();
_$2.forOwn(dd_1, function (value, key) {
viewModel.set(key, '');
});
return;
}
var dd = _$2.get(viewModel.getData(), propertyName);
_$2.forOwn(dd, function (value, key) {
viewModel.set(propertyName + '.' + key, '');
});
}
function reloadGrid(scope, gridRefName) {
var _a;
(_a = scope.refs[gridRefName]) === null || _a === void 0 ? void 0 : _a.reload();
}
/**
* 将 Ext.data.Model 对象 (及子属性) 转换为 js.object 对象
*/
function toPlainObject(obj) {
if (obj.isModel) {
obj = obj.data;
}
_$2.forOwn(obj, function (v, k) {
// Ext.data.Model.constructor
if (!v) {
return;
}
if (v.isModel) {
v = v.data;
}
if (typeof v === 'object') {
obj[k] = toPlainObject(v);
}
else {
obj[k] = v;
}
});
return obj;
}
function confirm(msg, sender) {
return new Promise(function (resolve) {
var _a, _b;
var scope = (_a = lookupScope(sender)) === null || _a === void 0 ? void 0 : _a.topScope;
var t = { msg: msg };
var WMSTranslate = window["WMSTranslate"];
if (WMSTranslate) {
if (typeof window['viewTranslate'] === 'function') {
window['viewTranslate'](t, msg, "msg");
}
}
var config = {
title: '请确认',
modal: true,
animateTarget: sender,
// resizable: false,
// constrainHeader: true,
// constrain: true,
// constrainTo: scope._handle?.el?.dom || Ext.getBody(),
layout: {
type: 'hbox',
pack: 'start',
align: 'stretch'
},
items: [
{
html: '',
border: false,
},
{
flex: 1,
border: false,
html: "
" + _$2.escape(t.msg) + "
"
}
],
buttons: [
{
xtype: 'button', text: '确定', iconCls: 'x-fa fa-check-circle',
handler: function () {
resolve();
win.close();
}
},
{
xtype: 'button', text: '取消', iconCls: 'x-fa fa-power-off',
handler: function () {
win.close();
}
}
],
keyMapEnabled: true,
keyMap: {
ENTER: function () {
resolve();
win.close();
}
}
};
if (scope === null || scope === void 0 ? void 0 : scope._handle) {
config.constrain = true;
}
var win = new Ext.Window(config);
if (scope === null || scope === void 0 ? void 0 : scope._handle) {
(_b = scope === null || scope === void 0 ? void 0 : scope._handle) === null || _b === void 0 ? void 0 : _b.add(win);
}
win.show();
});
}
/**
* 任何符号字符串都替换成下换线
*/
function normId(value) {
return _$2.replace(value, /[^\w]/g, '_');
}
/**
*
* @param sender
* @param propertyName
* @param gridRefName
*/
function clearViewModelReloadGrid(sender, propertyName, gridRefName) {
var _a, _b;
var scope = lookupScope(sender);
clearViewModelValues(scope.viewModel, propertyName);
if (!gridRefName) {
(_a = scope.down('grid')) === null || _a === void 0 ? void 0 : _a.reload();
}
else {
(_b = scope.refs[gridRefName]) === null || _b === void 0 ? void 0 : _b.reload();
}
}
var keydown_fun_item = _$2.debounce(function (sender, event, eOpts) {
if ([10, 13, 20, 40].includes(event.keyCode)) {
// 获取读码器读取的内容,最好不要从 viewModel 中取值,而是从 sender.rawValue 中取值
var value = _$2.trim(sender.rawValue);
raiseClick(eOpts.handle);
}
}, 150);
function saveGridRow(grid1) {
var _a;
var config = grid1.config;
var scope = lookupScope(grid1);
var saveRowValues = (_a = _$2.get(config, 'behavior.saveRowValues')) !== null && _a !== void 0 ? _a : {};
saveRowValues = calcObjectFlat(scope.viewModel.data, saveRowValues);
// "表格保存"的相关配置
var dbSaveConfig = {
columns: [],
dbTableName: _$2.get(config, 'behavior.dbTableName'),
saveRowValues: saveRowValues,
path: scope.originalVjson.__custom_path,
};
var _b = getGridEditRows(grid1), newRows = _b.newRows, modifyRows = _b.modifyRows, removeRecords = _b.removeRecords, rows = _b.rows, err = _b.err;
if (err) {
// 如果有异常就不保存
return;
}
// 构建"表格保存"的相关配置
for (var i = 0; i < config.columns.length; i++) {
var c = config.columns[i];
var v = {
dataIndex: c.dataIndex,
header: c.header,
dbColumn: c.dbColumn,
serverCreateValue: c.serverCreateValue,
dbIsDeleteKey: c.dbIsDeleteKey,
dbIsUpdateKey: c.dbIsUpdateKey,
dbUpdateEnable: c.dbUpdateEnable,
serverValueConvert: c.dbUpdateEnable,
};
if (c.editor) {
v.editor = {
xtype: c.editor.xtype,
required: c.editor.required,
};
}
dbSaveConfig.columns.push(v);
}
// 进行业务上的逻辑校验
var hasError = false;
_$2.forEach(rows, function (row, i) {
for (var i_1 = 0; i_1 < config.columns.length; i_1++) {
var c = config.columns[i_1];
var value = row[c.dataIndex];
if (_$2.get(c, 'editor.required') === true && isEmpty(value)) {
msg$1("\"" + c.header + "\" \u4E0D\u80FD\u4E3A\u7A7A!");
hasError = true;
return false;
}
if (c.xtype === 'checkcolumn') {
if (value === false && typeof c.uncheckedValue !== 'undefined') {
row[c.dataIndex] = c.uncheckedValue;
}
if (value === true && typeof c.checkedValue !== 'undefined') {
row[c.dataIndex] = c.checkedValue;
}
}
}
});
if (hasError) {
return;
}
// 设置当前界面为 "保存中..." 状态
grid1.setLoading(true);
invokeServer$1('/Dev@batchSave', {
newRows: newRows,
modifyRows: modifyRows,
removeRecords: removeRecords,
config: dbSaveConfig,
}).then(function (res) {
// 保存成功就提示一下,并重新载入数据 (根据 dataSource 的设置)
msg$1(res.msg);
grid1.reload();
}).catch(function (e) {
console.error(e);
showErrorDialog$1(_$2.toString(e));
}).finally(function () {
// 无论正常异常,关闭 "保存中..." 状态
grid1.setLoading(false);
});
}
function insertGridRow(grid1) {
var config = grid1.config;
var focusColumnAfterInsert = _$2.get(config, 'behavior.focusColumnAfterInsert');
var insertRow = {};
_$2.forEach(config.columns, function (c) {
var fn = c.createValue;
if (_$2.startsWith(fn, 'scope.') ||
_$2.startsWith(fn, 'system.')) {
var scope = lookupScope(grid1);
var fn2 = lookupFn(scope, fn, c);
if (_$2.isFunction(fn2)) {
var newValue = fn2();
if (!_$2.isUndefined(newValue)) {
insertRow[c.dataIndex] = newValue;
}
}
}
else if (_$2.isString(fn) && fn) {
insertRow[c.dataIndex] = fn;
}
});
grid1.appendEditRow(insertRow, focusColumnAfterInsert);
}
function commitMe(sender) {
var window = sender.up('window');
var scope = lookupScope(sender);
if (typeof scope['commit'] === 'function') {
scope['commit']().then(function (res) {
window.close();
});
}
}
function removeGridRow(grid1) {
var _a;
var config = grid1.config;
var rows = [];
if (grid1.selModel.selType === "rowmodel") {
rows.push(grid1.selection);
}
else {
(_a = grid1.getSelectionModel().getSelected()) === null || _a === void 0 ? void 0 : _a.eachRow(function (r) {
rows.push(r);
});
}
if (rows.length > 1) {
var batchRemoveConfirm = _$2.get(config, 'behavior.batchRemoveConfirm');
if (_$2.isUndefined(batchRemoveConfirm)) {
//不需要提示
_$2.forEach(rows, function (r) {
grid1.getStore().remove(r);
});
}
else {
var tip = _$2.replace(batchRemoveConfirm, '{count}', '' + rows.length);
confirm(tip).then(function () {
_$2.forEach(rows, function (r) {
grid1.getStore().remove(r);
});
});
}
}
else if (rows.length === 1) {
var singleRemoveConfirm = _$2.get(config, 'behavior.singleRemoveConfirm');
if (_$2.isUndefined(singleRemoveConfirm)) {
//不需要提示
grid1.getStore().remove(rows[0]);
}
else {
var tip_1 = _$2.replace(singleRemoveConfirm, '{count}', '' + rows.length);
_$2.forEach(config.columns, function (c) {
tip_1 = _$2.replace(tip_1, "{" + c.dataIndex + "}", rows[0].get(c.dataIndex));
});
confirm(tip_1).then(function () {
grid1.getStore().remove(rows[0]);
});
}
}
else {
msg$1('请选择要删除的数据!');
}
}
function moveUpGridRow(grid) {
grid.rowMoveUp();
}
function moveDownGridRow(grid) {
grid.rowMoveDown();
}
var SystemEventFu = /** @class */ (function () {
function SystemEventFu() {
}
SystemEventFu.prototype.moveUpGridRow = function () {
return function (sender) {
var grid1 = sender.up('yvgrid');
moveUpGridRow(grid1);
};
};
SystemEventFu.prototype.commitMe = function () {
return function (sender) {
commitMe(sender);
};
};
SystemEventFu.prototype.moveDownGridRow = function () {
return function (sender) {
var grid1 = sender.up('yvgrid');
moveDownGridRow(grid1);
};
};
SystemEventFu.prototype.saveGridRow = function () {
return function (sender) {
var grid1 = sender.up('yvgrid');
saveGridRow(grid1);
};
};
SystemEventFu.prototype.insertGridRow = function () {
return function (sender) {
var grid1 = sender.up('yvgrid');
insertGridRow(grid1);
};
};
SystemEventFu.prototype.removeGridRow = function () {
return function (sender) {
var grid1 = sender.up('yvgrid');
removeGridRow(grid1);
};
};
SystemEventFu.prototype.enterToClick = function (btnReferenceName) {
return function (sender, config) {
if (!config.listeners) {
config.listeners = {};
}
config.listeners.afterrender = function (sender) {
var scope = lookupScope(sender);
// $(sender.el.dom).on('keydown', (e) => {
// const xtype = Ext.fly(e.target).component.xtype
// if (xtype === 'textfield' && e.keyCode === 13) {
// Ext.defer(() => {
// raiseClick(scope.refs[btnReferenceName])
// })
// e.preventDefault()
// e.stopPropagation()
// return false
// }
// })
$(sender.el.dom).on('keyup', function (e) {
var tt = Ext.fly(e.target).component;
var xtype = tt === null || tt === void 0 ? void 0 : tt.xtype;
if ((xtype !== 'textfield' && xtype !== 'numberfield') ||
![10, 13, 20, 40].includes(e.keyCode)) {
return;
}
e.preventDefault();
e.stopPropagation();
keydown_fun_item(tt, e, { handle: scope.refs[btnReferenceName] });
return;
});
};
};
};
SystemEventFu.prototype.confirm = function (text, fn) {
return function (sender) {
var scope = lookupScope(sender);
var msg = calcExpress(scope.viewModel.data, text);
confirm(msg, sender).then(function () {
fn.call(scope, sender);
});
};
};
SystemEventFu.prototype.gridRemoveCurrentRow = function (gridRefName) {
return function (sender) {
var scope = lookupScope(sender);
var grid = scope.refs[gridRefName];
if (grid) {
var records = grid.getSelectionModel().getLastSelected();
grid.store.remove(records);
}
};
};
SystemEventFu.prototype.loadForm = function (invokeUrl, invokeParam,
//可以是 scope.XX / system.XX / string / lookup表达式
writeTarget) {
return function (sender) {
if (!invokeUrl) {
return;
}
var scope = lookupScope(sender);
scope.setLoading(true);
var data = scope.viewModel.data;
if (invokeParam) {
data = calcObjectFlat(data, invokeParam);
}
invokeServer$1(invokeUrl, data).then(function (res) {
if (res.success) {
if (typeof writeTarget === "string") {
_$2.forOwn(res.data, function (v, k) {
scope.viewModel.set(writeTarget + "." + k, v);
});
}
else if (typeof writeTarget === 'function') {
writeTarget.call(scope, res.data);
}
else if (typeof writeTarget === 'object') {
var ret = calcObjectFlat(res.data, writeTarget);
_$2.forOwn(ret, function (v, k) {
scope.viewModel.set(k, v);
});
}
}
else {
showErrorDialog$1(res.msg || '未知错误', sender);
}
}).catch(function (e) {
var _a, _b;
var msg = (_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.msg;
showErrorDialog$1(msg || e.toString(), sender);
}).finally(function () {
scope.setLoading(false);
});
};
};
SystemEventFu.prototype.commit = function (groovyUrl, arg0, successCallback) {
return function (sender) {
var scope = lookupScope(sender);
scope.setLoading(true);
var data = scope.viewModel.data;
if (arg0) {
data = calcObjectFlat(data, arg0);
}
invokeServer$1(groovyUrl, data).then(function (res) {
if (res.success) {
if (res.msg) {
msg(res.msg);
}
if (typeof successCallback === 'function') {
successCallback.call(scope, sender, res.data);
}
}
else {
showErrorDialog$1(res.msg || '未知错误', sender);
}
}).catch(function (e) {
var _a, _b;
var msg = (_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.msg;
showErrorDialog$1(msg || e.toString(), sender);
}).finally(function () {
scope.setLoading(false);
});
};
};
SystemEventFu.prototype.formCommit = function (groovyUrl, arg0) {
return function (sender) {
var scope = lookupScope(sender);
var form = scope.down('form');
if (form) {
// 如果下级有表单,就做表单校验
var valid = form.isValid();
if (!valid) {
return;
}
}
scope.setLoading(true);
var data = scope.viewModel.data;
if (arg0) {
data = calcObjectFlat(data, arg0);
}
invokeServer$1(groovyUrl, data).then(function (res) {
if (res.success) {
if (res.msg) {
msg(res.msg);
}
scope.dialogSuccess(res);
}
else {
showErrorDialog$1(res.msg || '未知错误', sender);
}
}).catch(function (e) {
var _a, _b;
var msg = (_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.msg;
showErrorDialog$1(msg || e.toString(), sender);
}).finally(function () {
scope.setLoading(false);
});
};
};
SystemEventFu.prototype.dialogSuccess = function (lookupObject) {
return function (sender) {
var scope = lookupScope(sender);
if (lookupObject) {
scope.dialogSuccess(calcObjectFlat(scope.viewModel.data, lookupObject));
}
else {
scope.dialogSuccess();
}
};
};
SystemEventFu.prototype.clearViewModelValues = function (propertyName) {
return function (sender) {
var scope = lookupScope(sender);
clearViewModelValues(scope.viewModel, propertyName);
};
};
SystemEventFu.prototype.getGrid = function (url) {
return function (sender, config) {
if (config.xtype == "combogridmulti") {
// @ts-ignore
require([url], function (grid) {
_$2.forOwn(grid.default, function (v, k) {
sender[k] = v;
sender.config[k] = v;
if (sender.rendered) {
// 已经渲染出来了,重新调用 reload 强制刷新
sender.reload();
}
});
});
}
else {
// @ts-ignore
require([url], function (grid) {
sender.grid = grid.default;
config.grid = grid.default;
});
}
};
};
SystemEventFu.prototype.clearViewModelReloadGrid = function (propertyName, gridRefName) {
return function (sender) {
clearViewModelReloadGrid(sender, propertyName, gridRefName);
};
};
SystemEventFu.prototype.reloadGrid = function (gridRefName) {
return function (sender) {
var _a, _b;
var scope = lookupScope(sender);
if (!gridRefName) {
(_a = scope.down('grid')) === null || _a === void 0 ? void 0 : _a.reload();
}
else {
(_b = scope.refs[gridRefName]) === null || _b === void 0 ? void 0 : _b.reload();
}
};
};
SystemEventFu.prototype.showDialog = function (url, lookupForData, successCallback) {
return function (sender) {
var scope = lookupScope(sender);
var data = scope.viewModel.data;
var param = calcObjectFlat(data, lookupForData);
// @ts-ignore
require([url], function (module) {
var ScopeClass = module.default;
var scope = new ScopeClass();
scope.success = successCallback;
scope.showDialog(sender, {}, { data: param });
});
};
};
SystemEventFu.prototype.showWidget = function (widgetUrl, lookup) {
return function (sender, queryValue) {
showWidget(widgetUrl, lookup, sender, queryValue);
};
};
SystemEventFu.prototype.clearViewModelByLookup = function (lookup) {
return function (sender) {
clearViewModelByLookup(sender, lookup);
};
};
SystemEventFu.prototype.closeMe = function (callBack) {
return function (sender) {
var scope = lookupScope(sender);
scope.close();
if (callBack) {
callBack.call(sender);
}
};
};
// 未完成
SystemEventFu.prototype.showDialogAndFillData = function (url, lookupForData, map) {
return function (sender) {
var scope = lookupScope(sender);
var data = scope.viewModel.data;
var billSetting = scope.billSetting;
var param = calcObjectFlat(data, lookupForData);
return new Promise(function (resolve, reject) {
var sf = function (scope) {
scope.success = function (dlgScope, dlgSender, reData) {
};
scope.showDialog(sender, {}, { data: param });
};
// @ts-ignore
require([url], function (module) {
// 业务描述文件
if (url.endsWith(".bill")) {
ScopeEngine.buildScopeFromBillFile(module.default).then(function (scope) {
sf(scope);
});
}
else { //原生yvanui文件
var ScopeClass = module.default;
var scope_1 = new ScopeClass();
sf(scope_1);
}
});
});
};
};
__decorate([
Lib({
title: '为某个表格,上移行',
author: '罗一帆', createAt: '2022-07-19', updateAt: '2022-07-19', type: 'system', category: '表格',
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "moveUpGridRow", null);
__decorate([
Lib({
title: '为某个表格,上移行',
author: '罗一帆', createAt: '2022-07-19', updateAt: '2022-07-19', type: 'system', category: '表格',
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "commitMe", null);
__decorate([
Lib({
title: '为某个表格,下移行',
author: '罗一帆', createAt: '2022-07-19', updateAt: '2022-07-19', type: 'system', category: '表格',
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "moveDownGridRow", null);
__decorate([
Lib({
title: '为某个表格,批量保存至数据库',
author: '罗一帆',
createAt: '2022-07-19',
updateAt: '2022-07-19',
type: 'system',
category: '表格',
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "saveGridRow", null);
__decorate([
Lib({
title: '为某个表格插入数据行',
author: '罗一帆',
createAt: '2022-07-19',
updateAt: '2022-07-19',
type: 'system',
category: '表格',
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "insertGridRow", null);
__decorate([
Lib({
title: '为某个表格删除所选数据行',
author: '罗一帆',
createAt: '2022-07-19',
updateAt: '2022-07-19',
type: 'system',
category: '表格',
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "removeGridRow", null);
__decorate([
Lib({
title: '按下回车键之后默认是否按下某个按钮',
author: '罗一帆',
createAt: '2021-07-02',
updateAt: '2021-07-02',
type: 'system',
category: '字典',
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "enterToClick", null);
__decorate([
Lib({
title: '弹出确认对话框,回答 YES 之后调用某方法',
author: '罗一帆',
createAt: '2021-07-06',
updateAt: '2021-07-06',
type: 'system',
category: '对话框',
}),
__param(0, LibParam('对话框的确认文字', 'string')),
__param(1, LibParam('确认之后的调用的方法', 'event')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "confirm", null);
__decorate([
Lib({
title: '删除表格当前的选中行(前端删除)',
author: '罗一帆',
createAt: '2021-07-08',
updateAt: '2021-07-08',
type: 'system',
category: '表格',
}),
__param(0, LibParam('表格引用名', 'refs')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "gridRemoveCurrentRow", null);
__decorate([
Lib({
title: '查询表单,如果 url 为空值,就取消查询',
author: '罗一帆',
createAt: '2021-07-06',
updateAt: '2021-07-06',
type: 'system',
category: '表单',
}),
__param(0, LibParam('后端服务路径', 'string')),
__param(1, LibParam('后端需要的数据,默认情况提交所有', 'lookup', true)),
__param(2, LibParam('提交成功后的回调', 'viewModel', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "loadForm", null);
__decorate([
Lib({
title: '提交(不做校验、不关闭窗体)',
author: '罗一帆',
createAt: '2021-07-02',
updateAt: '2021-07-02',
type: 'system',
category: '表单',
}),
__param(0, LibParam('后端服务路径', 'string')),
__param(1, LibParam('后端需要的数据,默认情况提交所有', 'lookup', true)),
__param(2, LibParam('提交成功后的回调', 'event', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "commit", null);
__decorate([
Lib({
title: '提交表单',
author: '罗一帆',
createAt: '2021-07-02',
updateAt: '2021-07-02',
type: 'system',
category: '表单',
}),
__param(0, LibParam('后端服务路径', 'string')),
__param(1, LibParam('后端需要的参数,默认情况提交所有', 'lookup', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "formCommit", null);
__decorate([
Lib({
title: '对话框成功回调',
author: '罗一帆',
createAt: '2021-07-02',
updateAt: '2021-07-02',
type: 'system',
category: '对话框',
}),
__param(0, LibParam('传回给父窗口的成功参数对象', 'lookup', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "dialogSuccess", null);
__decorate([
Lib({
title: '清空 viewModel 某个属性',
author: '罗一帆',
createAt: '2021-07-02',
updateAt: '2021-07-02',
type: 'system',
category: '表单',
}),
__param(0, LibParam('属性路径', 'viewModel', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "clearViewModelValues", null);
__decorate([
Lib({
title: '从其他资源获取表格设置',
author: '罗一帆',
createAt: '2021-07-02',
updateAt: '2021-07-02',
type: 'system',
category: '表单',
}),
__param(0, LibParam('定义文件', 'module')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "getGrid", null);
__decorate([
Lib({
title: '清空 viewModel 某个属性,并刷新表格',
author: '罗一帆',
createAt: '2021-07-02',
updateAt: '2021-07-02',
type: 'system',
category: '表单',
}),
__param(0, LibParam('清空的属性', 'viewModel')),
__param(1, LibParam('要刷新的表格', 'refs', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "clearViewModelReloadGrid", null);
__decorate([
Lib({
title: '刷新表格',
author: '罗一帆',
createAt: '2021-07-02',
updateAt: '2021-07-02',
type: 'system',
category: '表单',
}),
__param(0, LibParam('表格对象,不填的情况下就是第一个表格', 'refs', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "reloadGrid", null);
__decorate([
Lib({
title: '显示对话框',
author: '罗一帆',
createAt: '2021-07-02',
updateAt: '2021-07-02',
type: 'system',
category: '对话框',
}),
__param(0, LibParam('业务模块名', 'module')),
__param(1, LibParam('参数数据 lookup 表达式', 'lookup', true)),
__param(2, LibParam('成功回调(对话框成功结束后的回调方法)', 'event', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "showDialog", null);
__decorate([
Lib({
title: '弹出查找框(不借助 search)',
author: '罗一帆',
createAt: '2021-07-02',
updateAt: '2021-07-02',
type: 'system',
category: '对话框',
}),
__param(0, LibParam('模块名 (WidgetDialog)', 'module')),
__param(1, LibParam('lookup 映射关系', 'lookup', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "showWidget", null);
__decorate([
Lib({
title: '根据 lookup 清空 viewModel',
author: '罗一帆',
createAt: '2021-07-05',
updateAt: '2021-07-05',
type: 'system',
category: '表单',
}),
__param(0, LibParam('设值表达式', 'lookup')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "clearViewModelByLookup", null);
__decorate([
Lib({
title: '关闭对话框',
author: '罗一帆',
createAt: '2021-07-05',
updateAt: '2021-07-05',
type: 'system',
category: '对话框',
}),
__param(0, LibParam('对话框的返回值回调', 'event', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "closeMe", null);
__decorate([
Lib({
title: '打开对话框并返回数据',
author: '余亮',
createAt: '2022-07-07',
updateAt: '2022-07-07',
type: 'system',
category: '对话框',
}),
__param(0, LibParam('业务模块名', 'module')),
__param(1, LibParam('参数数据 lookup 表达式', 'lookup', true)),
__param(2, LibParam('结果映射关系', 'string', true)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, Object]),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "showDialogAndFillData", null);
return SystemEventFu;
}());
/**
* 清空 viewmodel 里下属的所有属性
* @param viewModel VM对象
* @param propertyKey 要清空的属性,可以是 "a.b.c" 这种表达模式
* @param ignoreProps 要忽略清空的属性名集合, 比如 ["a.b","b"]
*/
function clearViewModel(viewModel, propertyKey, ignoreProps) {
var data = viewModel.data;
if (propertyKey) {
data = _$2.get(data, propertyKey);
}
_$2.forOwn(data, function (value, key) {
var targetKey = propertyKey ? propertyKey + "." + key : key;
if (ignoreProps && _$2.indexOf(ignoreProps, targetKey) >= 0) {
return;
}
viewModel.set(targetKey, '');
});
}
function clearViewModelByLookup(sender, lookup) {
if (_$2.isPlainObject(lookup)) {
var parentScope_1 = lookupScope(sender);
_$2.forOwn(lookup, function (value, key) {
if (SIMPLE_RE.test(value)) {
// '{foo}' 简单表达式
var path = value.substring(1, value.length - 1);
if (path !== 'queryValue') {
parentScope_1.viewModel.set(path, '');
}
}
});
}
}
function showWidget(widgetUrl, lookup, sender, queryValue, vjson) {
if (vjson === void 0) { vjson = {}; }
var parentScope = lookupScope(sender);
var me = sender;
// @ts-ignore
require([widgetUrl], function (widgetScope) {
var WidgetScopeClass = widgetScope.default;
widgetScope = new WidgetScopeClass();
// 传递进 widget.model 的数据
var widgetDialogData = calcObjectFlat(__assign({ queryValue: queryValue }, parentScope.viewModel.data), lookup);
widgetScope.parentScope = parentScope;
widgetScope.searchWidgetSuccess = function (data) {
if (typeof lookup === 'string') {
// lookup 是字符串的情况下,就是取某个列作为 value 值
me.setValue(data[lookup]);
return;
}
/**
* lookup: {
* // 扩展到 viewModel 的值做更改
* WH_CODE: "{queryValue}",
* WH_NAME: "{query.WH_NAME}",
* }
*/
if (_$2.isPlainObject(lookup)) {
var parentScope_2 = lookupScope(sender);
tryWriteObject(lookup, data, function (path, value) {
if (path === 'queryValue') {
me.setValue(value);
}
else {
parentScope_2.viewModel.set(path, value);
}
});
}
return true;
};
widgetScope.showDialog(sender, vjson, { data: widgetDialogData });
});
}
/**
* 停止事件的默认行为
* @param e
*/
function stopEvent(e) {
e.preventDefault();
e.stopPropagation();
// @ts-ignore
window.event.cancelBubble = true;
e.returnValue = false;
e.cancelBubble = true;
}
/**
* 屏幕中央显示一个黑框提示
*/
function msg$1(content) {
msg(content);
}
/**
* 错误对话框的强提醒
*/
function showErrorDialog$1(msg, sender) {
showErrorDialog(msg, sender);
}
/**
* 错误对话框的强提醒
*/
function showInfoDialog(msg, sender) {
showInfoDialogSimple(msg, sender);
}
/**
* 错误对话框的强提醒
*/
function prompt$2(message, defaultValue, multiLine) {
if (defaultValue === void 0) { defaultValue = ""; }
if (multiLine === void 0) { multiLine = false; }
return prompt$1(message, defaultValue, multiLine);
}
/**
* 用于计算 express 表达式
*/
function evalFunction(data, express) {
var keys = [];
var values = [];
_$2.forOwn(data, function (value, key) {
var match = key.match(/\-|\*|\\|\/|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)/i);
if (match) {
key = key.substring(0, match.index);
}
keys.push(key);
values.push(value);
});
var func = Function.apply(void 0, __spread(keys, ['return ' + express]));
try {
return func.apply(void 0, __spread(values));
}
catch (e) {
return;
}
}
/**
* 获取表格编辑的行数据
*/
function getGridEditRows(grid) {
return grid.getGridEditRows();
}
var SystemLib = /*#__PURE__*/Object.freeze({
__proto__: null,
SIMPLE_RE: SIMPLE_RE,
pinyinMatch: pinyinMatch,
calcExpress: calcExpress,
calcObjectFlat: calcObjectFlat,
mergeViewModel: mergeViewModel,
flatRow: flatRow,
replaceNA: replaceNA,
deepTravJson: deepTravJson,
tryWriteByExpress: tryWriteByExpress,
tryWriteObject: tryWriteObject,
tryVarSimple: tryVarSimple,
calcObject: calcObject,
getParentGrid: getParentGrid,
tryEnable: tryEnable,
setComboStore: setComboStore,
invokeServer: invokeServer$1,
clearViewModelValues: clearViewModelValues,
reloadGrid: reloadGrid,
toPlainObject: toPlainObject,
confirm: confirm,
normId: normId,
clearViewModelReloadGrid: clearViewModelReloadGrid,
saveGridRow: saveGridRow,
insertGridRow: insertGridRow,
commitMe: commitMe,
removeGridRow: removeGridRow,
moveUpGridRow: moveUpGridRow,
moveDownGridRow: moveDownGridRow,
SystemEventFu: SystemEventFu,
clearViewModel: clearViewModel,
clearViewModelByLookup: clearViewModelByLookup,
showWidget: showWidget,
stopEvent: stopEvent,
msg: msg$1,
showErrorDialog: showErrorDialog$1,
showInfoDialog: showInfoDialog,
prompt: prompt$2,
evalFunction: evalFunction,
getGridEditRows: getGridEditRows
});
function initTree () {
Ext.define('Yvan.Tree', {
extend: 'Ext.tree.Panel',
alias: 'widget.yvtree',
xtype: 'yvtree',
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制性属性
}, baseConfig(config, 'row-item'), config, tree);
_$2.assign(newConfig, {
tbar: [
{
xtype: 'textfield',
// triggerCls: 'x-form-clear-trigger',
flex: 1,
emptyText: '搜索过滤',
enableKeyEvents: true,
listeners: {
change: function (sender) {
var tree = sender.up("treepanel");
tree.filterByText(this.getRawValue());
},
keyup: function (sender, e) {
var tree = sender.up("treepanel");
if (e.ESC === e.getKey()) {
sender.setValue('');
tree.filterByText('');
}
}
}
},
],
});
if (!newConfig.hideRefresh) {
newConfig.tbar.push({
xtype: 'button', iconCls: 'x-fa fa-refresh', tooltip: '刷新',
listeners: {
click: function (sender) {
var scope = sender.up("yvtree");
scope.reload();
}
}
});
}
if (!newConfig.hideExpand) {
newConfig.tbar.push({
xtype: 'button', iconCls: 'x-fa fa-plus-square-o', tooltip: '全部展开',
listeners: {
click: function (sender) {
var scope = sender.up("yvtree");
scope.expandAll();
}
}
});
}
if (!newConfig.hideCollapse) {
newConfig.tbar.push({
xtype: 'button', iconCls: 'x-fa fa-minus-square-o', tooltip: '全部收起',
listeners: {
click: function (sender) {
var scope = sender.up("yvtree");
scope.collapseAll();
}
}
});
}
this.superclass.constructor.call(this, newConfig);
},
/**
* 在根节点上增加一个节点,会触发 addNode 事件
* @param props
*/
addRoot: function (props) {
var me = this;
var tableNode = me.getRootNode();
var fieldNode = tableNode.createNode(new Ext.data.NodeInterface({}));
if (_$2.isFunction(props)) {
props = props.call(this, parent);
}
_$2.forOwn(props, function (value, key) {
fieldNode.set(key, value);
});
var node = tableNode.appendChild(fieldNode);
me.ensureVisible(node);
me.setSelection(node);
me.fireEvent('addNode', me, {
parent: tableNode,
node: node,
});
},
addLast: function (props) {
var me = this;
var sel = me.selModel.getSelection();
if (!sel || sel.length <= 0) {
msg('请选择一个要添加的同级节点路径');
return;
}
var parent = sel[0].parentNode ? sel[0].parentNode : me.getRootNode();
var fieldNode = parent.createNode(new Ext.data.NodeInterface({}));
if (_$2.isFunction(props)) {
props = props.call(this, parent);
}
_$2.forOwn(props, function (value, key) {
fieldNode.set(key, value);
});
var node = parent.appendChild(fieldNode);
me.ensureVisible(node);
me.setSelection(node);
me.fireEvent('addNode', me, {
parent: parent,
node: node,
});
},
addChildren: function (props) {
var me = this;
var sel = me.selModel.getSelection();
if (!sel || sel.length <= 0) {
msg('请选择一个要添加子节点的路径');
return;
}
var parent = sel[0];
if (_$2.isFunction(props)) {
props = props.call(this, parent);
}
var fieldNode = parent.createNode(new Ext.data.NodeInterface({}));
_$2.forOwn(props, function (value, key) {
fieldNode.set(key, value);
});
var node = parent.appendChild(fieldNode);
parent.expand();
me.ensureVisible(node);
me.setSelection(node);
me.fireEvent('addNode', me, {
parent: parent,
node: node,
});
},
initComponent: function () {
var me = this;
var config = me.config;
var scope = lookupScope(this);
if (!isDesignMode(scope, config)) {
// 转换 dataSource 属性
convertDataSource(me, scope, config);
}
this.superclass.initComponent.call(this);
this.on({
afterrender: function (sender) {
var me = this;
var config = this.config;
var dataSource = config.dataSource;
if (config.autoLoad) {
if (config.dataSourceCallbackFn) {
me.reload();
}
else if (_$2.isPlainObject(dataSource) && dataSource.method === 'invoke') {
me.reload();
}
}
}
});
},
_setDataReal: function (value) {
var me = this;
// me.setStore(new Ext.data.TreeStore({
// root: {
// expanded: true,
// // children: value
// children: [
// {
// id: '1', text: 'A',
// children: [
// {id: '1', text: 'A',},
// {id: '2', text: 'B'},
// ]
// },
// {id: '2', text: 'B'},
// ]
// }
// }))
me.store.setRoot({
expanded: true,
children: value
});
// me.store = new Ext.data.TreeStore({
// root: {
// expanded: true,
// // children: value
// children: [
// {
// id: '1', text: 'A',
// children: [
// {id: '1', text: 'A',},
// {id: '2', text: 'B'},
// ]
// },
// {id: '2', text: 'B'},
// ]
// }
// })
},
/**
* 重新载入数据(重新计算参数)
*/
reload: function (reloadParams) {
if (reloadParams === void 0) { reloadParams = {}; }
var me = this;
var config = me.config;
if (config.dataSourceCallbackFn) {
// 函数请求刷新
var scope_1 = lookupScope(this);
// me.setLoading(true)
config.dataSourceCallbackFn.call(scope_1, me, {
successCallback: function (value) {
me._setDataReal(value);
// me.setLoading(false)
me.fireEvent('dataLoadComplete', me, true, value);
},
failCallback: function (error) {
// me.setLoading(false)
me.fireEvent('dataLoadComplete', me, false, error);
}
});
return;
}
var scope = lookupScope(me);
var dataSource = config.dataSource;
if (_$2.isPlainObject(dataSource) && dataSource.method === 'invoke' && !isDesignMode(scope, config)) {
var params = calcObjectFlat(scope.viewModel.data, _$2.defaultsDeep({}, reloadParams, dataSource.params));
me.setLoading(true);
invokeServer$1(dataSource.url, params)
.then(function (res) {
me._setDataReal(res.data);
me.fireEvent('dataLoadComplete', me, res);
})
.finally(function () {
me.setLoading(false);
});
}
},
filterByText: function (text) {
this._filterText = text;
this._filterBy(this, text, 'text');
},
_filterBy: _$2.debounce(function (me, text, by) {
var view = me.getView();
me.store.clearFilter();
if (!me._filterText) {
// 没有筛选内容,还原状态
var selections = me.getSelection();
var selectionPaths_1 = [];
_$2.forEach(me.getSelection(), function (item) {
selectionPaths_1.push(item.getPath());
});
me.collapseAll();
_$2.forEach(selectionPaths_1, function (path) {
me.expandPath(path);
});
me.setSelection(selections);
return;
}
// 递归查找所有需要可见的节点 id 数组
var nodesAndParents = [];
var expandPaths = [];
me.getRootNode().cascadeBy(function (tree, view) {
var currNode = this;
currNode.collapse();
if (currNode && currNode.data[by] && pinyinMatch(currNode.data[by].toString(), text)) {
// 展开到匹配的路径
// me.expandPath(currNode.getPath());
expandPaths.push(currNode.getPath());
// 沿途父节点全部设定为可见
while (currNode.parentNode) {
nodesAndParents.push(currNode.id);
currNode = currNode.parentNode;
}
}
}, null, [me, view]);
me.store.filterBy(function (r) {
return Ext.Array.contains(nodesAndParents, r.get('id'));
});
_$2.forEach(expandPaths, function (path) {
me.expandPath(path);
});
}, 1000),
});
}
function convertDataSource(sender, scope, newConfig) {
if (typeof newConfig.store !== 'undefined') {
// 有 store 属性的情况下,不做任何事
return;
}
if (typeof newConfig.dataSource === 'undefined') {
// 没有定义 dataSource 的情况下,不做任何事
return;
}
var dataSource = newConfig.dataSource;
if (typeof dataSource === 'string') {
// dataSource 是字符串的情况下,找到成员函数
dataSource = lookupFn(scope, dataSource);
}
if (typeof dataSource === 'function') {
// dataSource 是函数的情况下,在 afterrender 之后进行回调
newConfig.store = new Ext.data.TreeStore({
root: {
expanded: true,
children: []
}
});
newConfig.dataSourceCallbackFn = dataSource;
return;
}
// throw new TypeError('无法识别的调用方法')
}
/**
* 构建一个 grid 支持的 dataSource
*/
function gridInvokeBuild(scope, grid, config, dataSource, reloadParams, isExcelExport, excelExportCallBack) {
if (reloadParams === void 0) { reloadParams = {}; }
if (isExcelExport === void 0) { isExcelExport = false; }
if (excelExportCallBack === void 0) { excelExportCallBack = null; }
var _a;
var me = grid;
var params = calcObjectFlat(scope.viewModel.data, dataSource.params);
var storeOption = {};
if (dataSource.method === 'invoke' || dataSource.sqlId) {
if (dataSource.sqlId) {
dataSource.method = 'invoke';
dataSource.url = '/Dev@executeSQL';
if (_$2.startsWith(dataSource.sqlId, '@')) {
// sqlId 是 @ 开头,代表直接带中文名
var scope_1 = lookupScope(grid);
params.path = sqlUrlTransform(_$2.get(scope_1, 'originalVjson.__custom_path'));
params.sqlId = dataSource.sqlId.substring(1);
}
else {
// sqlId 是 aa/bb/cc@dd 模式,代表直接带中文名
var _b = __read(dataSource.sqlId.split('@'), 2), path = _b[0], sqlId = _b[1];
params.path = path;
params.sqlId = sqlId;
}
params.pagination = (_a = config.pagination) !== null && _a !== void 0 ? _a : true;
}
var fields_1 = [];
_$2.forEach(grid.columns, function (col) {
var c = {};
if (col.dataIndex) {
c.name = col.dataIndex;
fields_1.push(c);
}
if (col.dataType) {
c.type = col.dataType;
}
});
// 默认支持 gridInvoke
var extraParams = _$2.defaultsDeep({}, reloadParams, params);
//@ts-ignore
storeOption = {
fields: fields_1,
remoteSort: config.remoteSort,
remoteFilter: config.remoteFilter,
autoLoad: true,
pageSize: me.store.pageSize || config.pageSize,
proxy: {
type: 'jsonAjax',
$owner: me,
url: serverInvokeUrlTransform(dataSource.url, { scope: scope, grid: grid, isExcelExport: isExcelExport, excelExportCallBack: excelExportCallBack }),
extraParams: extraParams,
reader: {
type: 'json',
rootProperty: 'data',
totalProperty: 'pagination.total',
successProperty: 'success',
messageProperty: 'msg',
transform: function (data) {
if (typeof window['ajaxProcess'] === 'function') {
window['ajaxProcess'](data);
}
if (typeof window['apiTranslate'] === 'function') {
window['apiTranslate'](data, dataSource.url);
}
if (typeof grid._transform === 'function') {
// 系统转换函数
grid._transform(data.data);
}
if (grid.dataTransform) {
if (typeof grid.dataTransform === 'string') {
grid.dataTransform = lookupFn(lookupScope(grid), grid.dataTransform);
}
return grid.dataTransform.call(scope, grid, data);
}
return data;
}
}
},
listeners: {
load: function (store, records, successful, operation) {
var _a, _b, _c;
var rep = (_a = operation.getResponse()) === null || _a === void 0 ? void 0 : _a.responseJson;
if (rep.pagination) {
grid.dbInfo = rep.pagination.dbInfo;
grid.exportDataSql = rep.pagination.exportDataSql;
grid.exportDataSqlParams = rep.pagination.exportDataSqlParams;
}
me.exportExcelTotal = ((_b = rep === null || rep === void 0 ? void 0 : rep.pagination) === null || _b === void 0 ? void 0 : _b.total) || ((_c = rep === null || rep === void 0 ? void 0 : rep.data) === null || _c === void 0 ? void 0 : _c.length) || 0;
if (isExcelExport) {
if (typeof excelExportCallBack === 'function') {
excelExportCallBack(rep);
}
else if (excelExportCallBack) {
console.error("导出回调方法错误!");
}
me.fireEvent('excelDataLoadComplete', me, successful, records);
}
else {
if (_$2.get(config, 'behavior.autoSelectFirst')) {
// 自动选中第一行
var data = grid.getStore().data;
if (data.length > 0) {
grid.setSelection(data.items[0]);
}
}
me.fireEvent('dataLoadComplete', me, successful, records);
}
}
}
};
}
else if (exports.apiConvert) {
// 外部扩展的 apiConvert
//@ts-ignore
storeOption = exports.apiConvert.gridInvokeBuild(scope, grid, config, dataSource, params, reloadParams, isExcelExport, excelExportCallBack);
}
else {
throw new TypeError("不支持的 API 请求方式");
}
if (isExcelExport) {
var excelStore = new Ext.data.Store(storeOption);
excelStore.load();
}
else {
if (me.groupField) {
console.log('groupField', storeOption.groupField);
storeOption.groupField = me.groupField;
}
me.setStore(new Ext.data.Store(storeOption));
}
}
function initStores () {
Ext.define('Yvan.JsonAjaxProxy', {
extend: 'Ext.data.proxy.Ajax',
alias: 'proxy.jsonAjax',
actionMethods: {
create: "POST",
read: "POST",
update: "POST",
destroy: "POST"
},
timeout: storeAjax.timeout,
buildRequest: function (operation) {
// 参考源码 ext-all-debug.js:71468 method:buildRequest
var me = this;
var $owner = me.$owner; // 在 grid.initComponent 中赋值 $owner
var scope = lookupScope($owner);
var gridParam = me.getParams(operation);
var customParam = {};
// 提取 srot 元素
if (gridParam.sort) {
var sort = JSON.parse(gridParam.sort);
// 字符串 [{"property":"BRANCHID","direction":"ASC"}]
// 转换为对象 [{colId: "BRANCHID", sort: "asc"}]
customParam.sortModel = [];
_$2.forEach(sort, function (s) {
customParam.sortModel.push({
colId: s.property,
sort: _$2.toLower(s.direction)
});
});
delete gridParam.sort;
}
// 提取筛选元素
if (gridParam.filter) {
var filter = JSON.parse(gridParam.filter);
console.log('gridParam.filter', gridParam.filter);
// "[{"operator":"like","value":"1","property":"id"}]"
// 转换为 filterModel: {BRANCHID: {filterType: "text", type: "contains", filter: "12"}}
customParam.filterModel = {};
_$2.forEach(filter, function (s) {
var newFilterItem = {};
if (s.operator === 'like') {
newFilterItem.filterType = 'text';
newFilterItem.type = 'contains';
newFilterItem.filter = s.value;
}
else {
// 无法识别的筛选类型
newFilterItem.filterType = 'dict';
newFilterItem.type = 'in';
newFilterItem.filter = s.value;
}
customParam.filterModel[s.property] = newFilterItem;
});
delete gridParam.filter;
}
// 被 grid.constructor 作为方法存在
var extraParams = _$2.cloneDeep(me.getExtraParams());
var params = _$2.defaultsDeep(gridParam, extraParams);
// var request = this.superclass.buildRequest.apply(this, arguments);
var request = new Ext.data.Request({
params: {},
action: operation.getAction(),
records: operation.getRecords(),
url: me.buildUrl(),
jsonData: __assign({ args: [
params
] }, customParam),
proxy: me
});
operation.setRequest(request);
return request;
},
afterRequest: function (req, res) {
// Extend.afterExtRequest(req, res)
}
});
Ext.define('Ext.ux.data.MyReader', {
extend: 'Ext.data.reader.Json',
xtype: 'yvgridreader',
useSimpleAccessors: false,
});
}
function initBehaviorEdit(config) {
var _a, _b, _c;
var dbTableName = _$2.get(config, 'behavior.dbTableName');
var addButtonConfig = (_a = _$2.get(config, 'behavior.addButtonConfig')) !== null && _a !== void 0 ? _a : {};
var deleteButtonConfig = (_b = _$2.get(config, 'behavior.deleteButtonConfig')) !== null && _b !== void 0 ? _b : {};
var saveButtonConfig = (_c = _$2.get(config, 'behavior.saveButtonConfig')) !== null && _c !== void 0 ? _c : {};
if (dbTableName) {
// 生成增删查改
var tbar = [
__assign({ xtype: 'button', text: '保存', iconCls: 'x-fa fa-save', cls: 'ext-btn-primary', listeners: {
click: 'system.saveGridRow()'
}, bind: {
disabled: '{!' + config.reference + '.ischanged}'
} }, saveButtonConfig),
'-',
__assign({ xtype: 'button', text: '添加', iconCls: 'x-fa fa-plus-circle', listeners: {
click: 'system.insertGridRow()'
} }, addButtonConfig),
__assign({ xtype: 'button', text: '删除', iconCls: 'x-fa fa-minus-circle', cls: 'ext-btn-danger', listeners: {
click: 'system.removeGridRow()'
} }, deleteButtonConfig),
];
if (_$2.isArray(config.tbar)) {
config.tbar = __spread(tbar, [
'-'
], config.tbar);
}
else if (_$2.isPlainObject(config.tbar)) {
config.tbar = {
border: false,
layout: {
type: 'vbox',
align: 'stretch'
},
items: [
{
xtype: 'toolbar',
border: false,
items: tbar
},
config.tbar,
]
};
}
else if (_$2.isUndefined(config.tbar)) {
config.tbar = tbar;
}
else {
console.error("can't build tbar property!", config.tbar);
}
}
}
function initGridDialog(config) {
var detailDialog = _$2.get(config, 'detailDialog');
var detailButtonConfig = _$2.get(config, 'behavior.detailButtonConfig');
if (_$2.isPlainObject(detailDialog)) {
var tbar = [
__assign({ xtype: 'button', text: '详情', iconCls: 'x-fa fa-id-card-o', listeners: {
click: 'system.showGridRowDetail()',
}, bind: {
disabled: '{!' + config.reference + '.selection}'
} }, detailButtonConfig)
];
if (_$2.isArray(config.tbar)) {
config.tbar = __spread(config.tbar, [
'-'
], tbar);
}
else if (_$2.isPlainObject(config.tbar)) {
if (_$2.get(config.tbar, 'layout.type') === 'vbox' || _$2.get(config.tbar, 'layout') === 'vbox') {
config.tbar.items = __spread(config.tbar.items);
var toolbar = _$2.find(config.tbar.items, function (item) { return item.xtype === 'toolbar'; });
if (!toolbar) {
config.tbar.items = __spread(config.tbar.items, [
{
xtype: 'toolbar',
border: false,
items: tbar
},
]);
}
else {
toolbar.items = __spread(toolbar.items, [
'-'
], tbar);
}
}
else {
config.tbar = {
border: false,
layout: {
type: 'vbox',
align: 'stretch'
},
items: [
{
xtype: 'toolbar',
border: false,
items: tbar
},
config.tbar,
]
};
}
}
else if (_$2.isUndefined(config.tbar)) {
config.tbar = tbar;
}
else {
console.error("can't build tbar property!", config.tbar);
}
}
}
var SystemEventFu$1 = /** @class */ (function () {
function SystemEventFu() {
}
SystemEventFu.prototype.showGridRowDetail = function () {
return function (sender) {
var grid1 = sender.up('yvgrid');
showGridRowDetail(grid1);
};
};
__decorate([
Lib({
title: '为某个表格所选数据行, 显示其对话框',
author: '罗一帆',
createAt: '2022-07-27',
updateAt: '2022-07-27',
type: 'system',
category: '表格',
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], SystemEventFu.prototype, "showGridRowDetail", null);
return SystemEventFu;
}());
function showGridRowDetail(grid1, isEdit) {
if (isEdit === void 0) { isEdit = true; }
var _a, _b, _c;
if (!grid1.selection) {
msg$1('请选中要展示的数据行!');
return;
}
var record = grid1.selection;
if (_$2.isArray(record)) {
record = record[0];
}
if (!record) {
msg$1('请选中要展示的数据行!');
return;
}
var config = grid1._originVJson;
var detailDialog = config.detailDialog;
var vjson = {};
var parentScope = lookupScope(grid1);
var __custom_path = _$2.get(parentScope, 'originalVjson.__custom_path');
var __custom_version = _$2.get(parentScope, 'originalVjson.__custom_version');
_$2.defaultsDeep(vjson, {
// 强制属性
layout: 'fit',
__custom_path: __custom_path,
__custom_version: __custom_version,
fbar: __spread([
{ xtype: 'button', iconCls: 'x-fa fa-save', text: '确定', listeners: { click: 'system.commitMe()' } },
{ xtype: 'button', iconCls: 'x-fa fa-times', text: '取消', listeners: { click: 'system.closeMe()' } }
], ((_a = detailDialog.fbar) !== null && _a !== void 0 ? _a : [])),
items: (_b = detailDialog.items) !== null && _b !== void 0 ? _b : [],
}, detailDialog, {
// 默认属性
width: 800,
height: 450,
bind: __assign({ title: '{_editType}' }, ((_c = detailDialog.bind) !== null && _c !== void 0 ? _c : {})),
});
if (_$2.isPlainObject(detailDialog.tabpanel)) {
var tabpanel = __assign({ xtype: 'tabpanel' }, _$2.cloneDeep(detailDialog.tabpanel));
vjson.items.push(tabpanel);
if (tabpanel) {
// 有多个选项卡,按每个选项卡进行过滤
_$2.forEach(tabpanel.items, function (tab) {
var tabColumns = _$2.filter(config.columns, function (c) { var _a; return ((_a = c.form) === null || _a === void 0 ? void 0 : _a.tab) === tab.title; });
if (tabColumns.length > 0) {
var tabVjson = buildForm(tabColumns, undefined, detailDialog);
_$2.extend(tab, tabVjson);
}
});
}
}
else {
vjson.items.push(buildForm(config.columns, undefined, detailDialog));
}
var model = {
data: {
_edit: isEdit,
_editType: isEdit ? '编辑' : '添加',
}
};
_$2.forOwn(record.data, function (value, key) {
if (key === 'id') {
// 忽略 ID 属性
return;
}
if (_$2.startsWith(key, '_')) {
// 忽略 _ 开头的所有属性
return;
}
model.data[key] = value;
});
console.log(vjson);
var scope = new Scope({ vjson: vjson, model: model, });
//@ts-ignore
scope.commit = function () {
return new Promise(function (resolve) {
_$2.forOwn(scope.viewModel.data, function (value, key) {
if (_$2.startsWith(key, '_')) {
// _origin 等属性可以被忽略
return;
}
if (key === 'id') {
// id 属性被忽略
return;
}
record.set(key, value);
});
resolve();
});
};
scope.showDialog(grid1, {}, {});
}
function buildForm(columns, tabpanel, detailDialog) {
var vjson = __assign({ border: false, layout: {
type: 'vbox',
pack: 'start',
align: 'stretch'
}, defaults: {
border: false,
anchor: '100%',
margin: '5',
}, scrollable: true, items: [] }, detailDialog.form);
var emptyFieldset = [];
var fieldsetList = [];
columns = _$2.sortBy(columns, function (c) { var _a; return (_a = _$2.get(c, 'form.order')) !== null && _a !== void 0 ? _a : 1; });
_$2.forEach(columns, function (c) {
var fieldset = _$2.get(c, 'form.fieldset');
if (fieldset) {
var idx = _$2.findIndex(fieldsetList, function (t) { return t.fieldset === fieldset; });
if (idx < 0) {
fieldsetList.push({
fieldset: fieldset,
columns: [c]
});
}
else {
fieldsetList[idx].columns.push(c);
}
}
else {
emptyFieldset.push(c);
}
});
_$2.forEach(fieldsetList, function (fs) {
var fieldSetVjson = {
xtype: 'fieldset',
title: fs.fieldset,
items: []
};
buildFieldItems(fieldSetVjson.items, fs.columns);
vjson.items.push(fieldSetVjson);
});
buildFieldItems(vjson.items, emptyFieldset);
return vjson;
}
// 构建字段组
function buildFieldItems(items, columns) {
var _a, _b, _c, _d, _e;
var row = {
xtype: 'cols',
items: []
};
for (var i = 0; i < columns.length; i++) {
var column = columns[i];
if ((_a = column.form) === null || _a === void 0 ? void 0 : _a.rowlayout) {
delete row.xtype;
row.layout = column.form.rowlayout;
}
if ((_b = column.form) === null || _b === void 0 ? void 0 : _b.prefix) {
row.items.push({ border: false, flex: column.form.prefix });
}
var fieldVjson = buildField(column, row.items.length);
if (!fieldVjson) {
continue;
}
row.items.push(fieldVjson);
if ((_c = column.form) === null || _c === void 0 ? void 0 : _c.suffix) {
row.items.push({ border: false, flex: (_d = column.form) === null || _d === void 0 ? void 0 : _d.suffix });
}
if ((_e = column.form) === null || _e === void 0 ? void 0 : _e.wrap) {
items.push(row);
row = {
xtype: 'cols',
items: []
};
}
}
if (row.items.length > 0) {
items.push(row);
}
}
// 构建字段
function buildField(column, colIdx) {
var ret;
if (column.xtype === 'checkcolumn') {
ret = _$2.defaultsDeep({
xtype: 'checkbox',
uncheckedValue: column.uncheckedValue,
checkedValue: column.checkedValue,
boxLabel: column.header,
bind: {
value: '{' + column.dataIndex + '}'
}
}, column.form);
if (colIdx == 0) {
// 第一列的checkbox, 要向左空出 85 像素, 预留出 labelWidth
ret.margin = '0 0 0 85';
}
}
else {
ret = _$2.defaultsDeep({}, column.form, column.editor, {
fieldLabel: column.header,
bind: {
value: '{' + column.dataIndex + '}'
},
});
}
if (!ret.xtype) {
return;
}
if (!ret.dict && ret.xtype === 'combo') {
ret.dict = column.dict;
}
// 删除辅助属性
delete ret.order;
delete ret.wrap;
return ret;
}
var model$o = {
data: {}
};
var vjson$o = {
title: '自定义表格属性',
layout: 'fit',
width: 980,
height: 500,
fbar: [
{
xtype: "button",
text: "保存",
iconCls: 'x-fa fa-save',
listeners: {
click: 'scope.commit',
}
},
{
xtype: "button",
text: "关闭",
iconCls: 'x-fa fa-times',
listeners: {
click: 'system.closeMe()',
}
},
],
items: [
{
region: 'center',
xtype: 'tabpanel',
items: [
{
title: '基本信息', reference: 'basic',
layout: {
type: 'vbox',
pack: 'start',
align: 'stretch'
},
defaults: {
border: false,
anchor: '100%',
margin: '5',
},
scrollable: true,
items: [
{
xtype: 'cols',
items: [
{
fieldLabel: '路径',
bind: { value: '{__custom_path}' },
xtype: 'textfield',
flex: 2,
},
{
fieldLabel: '版本',
bind: { value: '{__custom_version}' },
xtype: 'textfield',
},
]
},
{
xtype: 'cols',
items: [
{
fieldLabel: '配置点',
bind: { value: '{__custom_point}' },
xtype: 'textfield',
},
{
fieldLabel: 'reference',
bind: { value: '{reference}' },
xtype: 'textfield',
},
{
fieldLabel: '编辑模式',
bind: { value: '{_mode}' },
xtype: 'combo',
dict: 'GRID_MODE',
},
]
},
{
layout: 'hbox',
defaults: {
margin: '0 0 0 15',
},
items: [
{
boxLabel: '隐藏底部工具栏', margin: '0 0 0 85', xtype: 'checkbox',
bind: {
value: "{hideFootbar}"
}
},
{
boxLabel: '隐藏刷新', xtype: 'checkbox',
bind: {
value: "{hideRefresh}"
}
},
{
boxLabel: '隐藏导出', xtype: 'checkbox',
bind: {
value: "{hideExport}"
}
},
{
boxLabel: '隐藏自动调宽', xtype: 'checkbox',
bind: {
value: "{hideAutoSize}"
}
},
{
boxLabel: '隐藏清空筛选', xtype: 'checkbox',
bind: {
value: "{hideClearFilter}"
}
},
{
boxLabel: '隐藏保存布局', xtype: 'checkbox',
bind: {
value: "{hideSaveGridUIConfig}"
}
},
{
boxLabel: '隐藏重置布局', xtype: 'checkbox',
bind: {
value: "{hideClearGridUIConfig}"
}
},
]
},
{
layout: 'hbox',
defaults: {
margin: '0 0 0 15',
},
items: [
{
boxLabel: '自动载入数据源', xtype: 'checkbox',
bind: { value: '{autoLoad}' },
margin: '0 0 0 85',
},
{
boxLabel: '分页模式', xtype: 'checkbox',
bind: { value: '{pagination}' },
},
{
boxLabel: '显示行序号', xtype: 'checkbox',
bind: { value: '{show_rownum}' },
},
{
boxLabel: '后端排序', xtype: 'checkbox',
bind: {
value: "{remoteSort}"
}
},
{
boxLabel: '后端过滤', xtype: 'checkbox',
bind: {
value: "{remoteFilter}"
}
},
{
boxLabel: '隐藏', xtype: 'checkbox',
bind: {
value: "{hidden}"
}
},
]
},
{
layout: 'hbox',
defaults: {
margin: '0 0 0 15',
},
items: [
{
boxLabel: '自定义隐藏', xtype: 'checkbox', margin: '0 0 0 85',
bind: {
value: "{enableColumnHide}"
}
},
{
boxLabel: '用户拖拽字段', xtype: 'checkbox',
bind: {
value: "{enableColumnMove}"
}
},
{
boxLabel: '自定义筛选', xtype: 'checkbox',
bind: {
value: "{gridfilters}"
}
},
{
boxLabel: '用户拖拽字段宽度', xtype: 'checkbox',
bind: {
value: "{enableColumnResize}"
}
},
{
boxLabel: '点击列头排序', xtype: 'checkbox',
bind: {
value: "{sortOnClick}"
}
},
]
},
{
xtype: 'cols',
items: [
{
fieldLabel: 'dbTableName',
labelWidth: 110,
bind: { value: '{behavior.dbTableName}' },
xtype: 'textfield',
},
{
fieldLabel: 'theid',
bind: { value: '{theid}' },
xtype: 'textfield',
},
{
fieldLabel: '添加行聚焦',
bind: { value: '{behavior.focusColumnAfterInsert}' },
xtype: 'textfield',
},
]
},
{
xtype: 'cols',
items: [
{
fieldLabel: '批量删除提示',
labelWidth: 110,
bind: { value: '{behavior.batchRemoveConfirm}' },
xtype: 'textfield',
},
{
fieldLabel: '删除提示',
bind: { value: '{behavior.singleRemoveConfirm}' },
xtype: 'textfield',
},
{
fieldLabel: '触发刷新',
labelWidth: 110,
bind: { value: '{behavior.selectToReload}' },
xtype: 'textfield',
},
]
},
]
},
{
title: '字段', reference: 'grid1',
xtype: 'yvgrid',
pagination: false,
_mode: 'edit',
listeners: {
buttonclick: 'scope.grid1Buttonclick',
},
hideFootbar: true,
tbar: [
{
xtype: 'button',
text: '添加',
iconCls: 'x-fa fa-plus-circle',
listeners: {
click: 'scope.addField'
}
},
{
xtype: 'button',
text: '删除',
iconCls: 'x-fa fa-minus-circle',
listeners: {
click: 'scope.removeField'
}
},
'-',
{
xtype: 'button',
text: '自动分析',
iconCls: 'x-fa fa-code-fork',
listeners: {
click: 'scope.calcField'
}
},
{
xtype: 'button',
text: '上移',
iconCls: 'x-fa fa-arrow-up',
listeners: {
click: 'scope.moveUp'
}
},
{
xtype: 'button',
text: '下移',
iconCls: 'x-fa fa-arrow-down',
listeners: {
click: 'scope.moveDown'
}
},
],
store: {},
columns: [
{
dataIndex: 'dataIndex', header: "字段名", width: 140,
editor: { xtype: 'textfield' }
},
{
dataIndex: 'dbColumn', header: "数据库字段", width: 140,
editor: { xtype: 'textfield' }
},
{
dataIndex: 'header', header: '中文', width: 140,
editor: { xtype: 'textfield' }
},
{
dataIndex: 'dict', header: '字典', width: 110,
editor: { xtype: 'combogrid' }
},
{
dataIndex: 'editor_widget', header: '下拉表', width: 110,
editor: { xtype: 'combogrid' }, hidden: true,
},
{
dataIndex: 'width', header: '宽度', width: 80,
editor: { xtype: 'numberfield' }, hidden: true,
},
{
dataIndex: 'editor_xtype', header: '编辑器', width: 170,
editor: { xtype: 'combo' }, dict: 'GRID_XTYPE'
},
{
dataIndex: 'serverCreateValue', header: '服务端创建值',
editor: { xtype: 'textfield' },
},
{
dataIndex: 'createValue', text: '客户端新创建值',
editor: { xtype: 'textfield' },
},
{
dataIndex: 'dbIsDeleteKey', text: '删除键', xtype: 'checkcolumn', width: 60,
resizable: false, sortable: false, menuDisabled: true,
checkedValue: true, uncheckedValue: false,
},
{
dataIndex: 'dbIsUpdateKey', text: '更新键', xtype: 'checkcolumn', width: 60,
resizable: false, sortable: false, menuDisabled: true,
checkedValue: true, uncheckedValue: false,
},
{
dataIndex: 'dbUpdateDisable', text: '禁更新', xtype: 'checkcolumn', width: 60,
resizable: false, sortable: false, menuDisabled: true,
checkedValue: true, uncheckedValue: false,
},
{
dataIndex: 'formatter', header: '格式化', width: 110,
editor: { xtype: 'combo' }, dict: 'GRID_FORMATTER', hidden: true,
},
{
dataIndex: 'resizable', text: '调整宽', xtype: 'checkcolumn', width: 60,
resizable: false, sortable: false, menuDisabled: true,
checkedValue: true, uncheckedValue: false, hidden: true,
},
{
dataIndex: 'editor_required', text: '必填', xtype: 'checkcolumn', width: 50,
resizable: false, sortable: false, menuDisabled: true,
hidden: true,
},
{
dataIndex: 'filterable', text: '过滤', xtype: 'checkcolumn', width: 50,
resizable: false, sortable: false, menuDisabled: true,
checkedValue: true, uncheckedValue: false, hidden: true,
},
{
dataIndex: 'hidden', text: '隐藏', xtype: 'checkcolumn', width: 50,
resizable: false, sortable: false, menuDisabled: true,
},
{
dataIndex: 'sortable', text: '排序', xtype: 'checkcolumn', width: 50,
resizable: false, sortable: false, menuDisabled: true,
checkedValue: true, uncheckedValue: false, hidden: true,
},
{
dataIndex: 'form_order', text: '对话框序号',
editor: { xtype: 'numberfield' },
},
{
dataIndex: 'form_xtype', text: '框换行', xtype: 'checkcolumn', width: 60,
resizable: false, sortable: false, menuDisabled: true,
checkedValue: true, uncheckedValue: false,
},
{
dataIndex: 'form_xtype', text: '对话框编辑器',
editor: { xtype: 'combo' }, dict: 'FORM_XTYPE', hidden: true,
},
{
dataIndex: 'form_fieldset', text: '对话框字段组',
editor: { xtype: 'textfield' }, hidden: true,
},
{
dataIndex: 'form_tab', text: '对话框选项卡',
editor: { xtype: 'textfield' }, hidden: true,
},
{
dataIndex: 'form_readonly', text: '框只读', xtype: 'checkcolumn', width: 60,
resizable: false, sortable: false, menuDisabled: true,
checkedValue: true, uncheckedValue: false, hidden: true,
},
],
},
{
title: 'SQL和查询条件', reference: 'sql',
layout: 'border',
border: false,
items: [
{
region: 'north',
height: 200,
border: false,
split: true,
xtype: 'yvgrid',
reference: 'gridCondition',
pagination: false,
hideFootbar: true,
_mode: 'edit',
listeners: {
buttonclick: 'scope.conditionButtonclick',
},
store: {},
tbar: {
xtype: 'toolbar',
border: false,
items: [
{
xtype: 'button',
text: '添加条件',
iconCls: 'x-fa fa-plus-circle',
listeners: {
click: 'scope.addCondition'
}
},
{
xtype: 'button',
text: '删除条件',
iconCls: 'x-fa fa-minus-circle',
listeners: {
click: 'scope.removeCondition'
}
},
'-',
{
xtype: 'button',
text: '自动分析条件变量',
iconCls: 'x-fa fa-code-fork',
listeners: {
click: 'scope.calcCondition'
}
},
{
xtype: 'button',
text: '上移',
iconCls: 'x-fa fa-arrow-up',
listeners: {
click: 'scope.moveUpCondition'
}
},
{
xtype: 'button',
text: '下移',
iconCls: 'x-fa fa-arrow-down',
listeners: {
click: 'scope.moveDownCondition'
}
},
]
},
columns: [
{
text: '条件变量',
dataIndex: 'param_name',
width: 140,
sortable: false,
menuDisabled: true,
editor: {
selectOnFocus: true
},
},
{
text: '中文标题',
dataIndex: 'fieldLabel',
width: 120,
sortable: false,
menuDisabled: true,
editor: {
selectOnFocus: true
},
},
{
text: '编辑类型',
dataIndex: 'xtype',
width: 80,
sortable: false,
menuDisabled: true,
editor: {
xtype: 'combo',
typeAhead: true,
triggerAction: 'all',
selectOnFocus: true,
store: [
['textfield', 'textfield'],
['combo', 'combo'],
['datefield', 'datefield'],
['datetimefield', 'datetimefield'],
['numberfield', 'numberfield'],
['multiplesearch', 'multiplesearch'],
]
}
},
{
text: '权重',
dataIndex: 'conditionFieldFlex',
align: 'right',
width: 60,
sortable: false,
menuDisabled: true,
editor: {
xtype: 'numberfield',
selectOnFocus: false,
minValue: 0,
maxValue: 10
},
},
{
text: '字典',
dataIndex: 'conditionFieldDict',
width: 160,
sortable: false,
menuDisabled: true,
editor: {
selectOnFocus: false
},
},
{
xtype: 'checkcolumn',
dataIndex: "conditionFieldWrap", header: "换行",
width: 65,
sortable: false,
menuDisabled: true,
},
{
text: '扩展参数',
dataIndex: 'conditionFieldExtend',
sortable: false,
menuDisabled: true,
editor: {
selectOnFocus: false
},
},
]
},
{
region: 'center',
xtype: 'sqleditor',
layout: 'fit',
reference: 'sqlEditor',
split: true,
},
]
},
{
title: '详情对话框',
layout: {
type: 'vbox',
pack: 'start',
align: 'stretch'
},
defaults: {
border: false,
anchor: '100%',
margin: '5',
},
scrollable: true,
items: [
{
xtype: 'cols',
items: [
{
fieldLabel: '对话框标题',
bind: { value: '{detailDialog.title}' },
xtype: 'textfield',
flex: 2,
},
{
fieldLabel: '宽度',
bind: { value: '{detailDialog.width}' },
xtype: 'numberfield',
},
{
fieldLabel: '高度',
bind: { value: '{detailDialog.height}' },
xtype: 'numberfield',
},
]
},
]
},
{
title: '界面源码',
xtype: 'jseditor',
reference: 'jseditor'
}
]
}
]
};
var GridColumnCustom = /** @class */ (function (_super) {
__extends(GridColumnCustom, _super);
function GridColumnCustom() {
return _super.call(this, { model: model$o, vjson: vjson$o }) || this;
}
GridColumnCustom.prototype.commit = function () {
};
GridColumnCustom.prototype.grid1Buttonclick = function () {
};
GridColumnCustom.prototype.conditionButtonclick = function () {
};
GridColumnCustom.prototype.addField = function () {
};
GridColumnCustom.prototype.removeField = function () {
};
GridColumnCustom.prototype.calcField = function () {
};
GridColumnCustom.prototype.moveUp = function () {
};
GridColumnCustom.prototype.moveDown = function () {
};
GridColumnCustom.prototype.addCondition = function () {
};
GridColumnCustom.prototype.removeCondition = function () {
};
GridColumnCustom.prototype.calcCondition = function () {
};
GridColumnCustom.prototype.moveUpCondition = function () {
};
GridColumnCustom.prototype.moveDownCondition = function () {
};
return GridColumnCustom;
}(Scope));
function initGridCode(grid, newConfig, buttons) {
if (typeof newConfig.__custom_point === "string" && newConfig.__custom_point) {
buttons.push({
xtype: 'button',
tooltip: '定义表格属性',
iconCls: 'x-fa fa-codepen',
handler: function (btn) {
var customWindow = new GridColumnCustom();
customWindow.showDialog(btn, {}, {});
}
});
buttons.push({
xtype: 'button',
tooltip: '定义表格数据源',
iconCls: 'x-fa fa-database',
handler: function () {
// showCustomGridDataSource(grid)
}
});
}
}
window["EXPORT_DATA_HOST"] = "http://127.0.0.1:30000/exportData";
var hexToString = function (hex) {
var arr = hex.split("");
var out = "";
for (var i = 0; i < arr.length / 2; i++) {
var tmp = "0x" + arr[i * 2] + arr[i * 2 + 1];
// @ts-ignore
var charValue = String.fromCharCode(tmp);
out += charValue;
}
return out;
};
var defaultGrid = grid;
function initGrid () {
Ext.define('Yvan.Grid', {
extend: 'Ext.grid.Panel',
xtype: 'yvgrid',
__suspendReload: false,
_originVJson: {},
constructor: function (config) {
var _this = this;
var _a, _b, _c, _d, _e, _f;
var me = this;
var dataSource = config.dataSource;
var scope = ((_a = config.$initParent) === null || _a === void 0 ? void 0 : _a.yvanScope) || ((_c = (_b = config.$initParent) === null || _b === void 0 ? void 0 : _b.lookupReferenceHolder()) === null || _c === void 0 ? void 0 : _c.yvanScope) || ((_d = config.$vmParent) === null || _d === void 0 ? void 0 : _d.yvanScope) || ((_f = (_e = config.$vmParent) === null || _e === void 0 ? void 0 : _e._parent) === null || _f === void 0 ? void 0 : _f.yvanScope);
me._originVJson = config;
if (!isDesignMode(scope, config)) {
this.columnConfigCacheKey = this.makeColumnConfigCacheKey(config);
if (Array.isArray(config.columns) && config.columns.length > 0) {
var cacheData = this.getColumnConfigCache();
if (Array.isArray(cacheData) && cacheData.length > 0) {
var newColumns = [];
for (var j = 0; j < cacheData.length; j++) {
var itData = cacheData[j];
for (var i = 0; i < config.columns.length; i++) {
var column = config.columns[i];
if (itData.dataIndex === column.dataIndex) {
if (itData.width) {
column.width = itData.width;
}
column.hidden = itData.hidden;
column.locked = itData.locked;
newColumns.push(column);
break;
}
}
}
config.columns = newColumns;
}
}
}
var newConfig = _$2.defaultsDeep({
// 强制性属性 bug.
// lock 属性会造成 Cannot read properties of undefined (reading 'els')
// enableLocking: false,
// syncRowHeight: false,
}, baseConfig(config, 'row-item'), config, grid);
// 在面板上的组件
// const scope = newConfig.$initParent?.yvanScope ||
// newConfig.$initParent?.lookupReferenceHolder()?.yvanScope ||
// config.$vmParent?.yvanScope ||
// newConfig.$vmParent?._parent?.yvanScope;
var buttons = [];
var getRowClass = newConfig.getRowClass;
if (typeof getRowClass === 'string' && (_$2.startsWith(getRowClass, "scope.") ||
_$2.startsWith(getRowClass, "system."))) {
var fn = lookupFn(scope, getRowClass);
_$2.set(newConfig, 'viewConfig.getRowClass', fn);
}
if (!newConfig.hideExport) {
buttons.push({
xtype: 'button',
tooltip: '导出Excel',
iconCls: 'x-fa fa-download',
listeners: {
click: this.exportExcel
},
});
}
if (!newConfig.hideAutoSize) {
buttons.push({
xtype: 'button',
iconCls: 'x-fa fa-text-width',
tooltip: '自适应宽度',
listeners: {
click: this.autoSizeColumns
}
});
}
if (!newConfig.hideClearFilter) {
buttons.push({
xtype: 'button',
tooltip: '清空筛选',
iconCls: 'x-fa fa-filter',
handler: this.clearFilter
});
}
if (!newConfig.hideSaveGridUIConfig) {
buttons.push({
xtype: 'button',
tooltip: '保存布局',
iconCls: 'x-fa fa-cogs',
handler: this.saveGridUIConfig
});
}
if (!newConfig.hideClearGridUIConfig) {
buttons.push({
xtype: 'button',
tooltip: '还原布局',
iconCls: 'x-fa fa-reply-all',
handler: this.clearGridUIConfig
});
}
initGridCode(me, newConfig, buttons);
if (!newConfig.hideFootbar) {
if (newConfig.pagination) {
newConfig.bbar = new Ext.PagingToolbar({
// pageSize: newConfig.pageSize, 这个值是无效的
displayInfo: true,
store: this.store,
emptyMsg: '没有记录',
cls: 'grid-bbar',
items: __spread([
{
xtype: 'combobox',
tooltip: '分页',
queryMode: 'local',
editable: false,
allowBlank: true,
labelAlign: 'right',
width: 90,
// labelWidth: 30,
listConfig: {
minWidth: null
},
value: 50,
valueField: undefined,
displayField: undefined,
hideClear: true,
store: newConfig.pageSizeOption,
listeners: {
change: function (sender, nv, ov) {
_this.store.pageSize = nv;
_this.store.loadPage(1);
}
}
}
], buttons),
doRefresh: function () {
me.reload();
}
});
}
else {
newConfig.bbar = {
xtype: 'toolbar', overflowHandler: 'menu',
cls: 'grid-bbar',
items: __spread([
{
xtype: 'button',
tooltip: '刷新',
iconCls: 'x-fa fa-refresh',
handler: function () {
_this.reload();
}
},
'-'
], buttons)
};
if (newConfig.hideRefresh) {
newConfig.bbar.items.splice(0, 1);
}
}
}
if (_$2.isArray(newConfig.condition)) {
// 带查询条件
var conditionRows_1 = [];
var newRow_1 = false;
var currentRow_1 = { xtype: 'cols', items: [], };
conditionRows_1.push(currentRow_1);
_$2.forEach(newConfig.condition, function (item) {
var _a;
if (newRow_1) {
currentRow_1 = { xtype: 'cols', items: [], };
conditionRows_1.push(currentRow_1);
}
var vj = _$2.cloneDeep(item);
if (vj.xtype) {
if (item.xtype === 'combo' && item.dict) {
vj.fix = ['system.getDict("' + item.dict + '")'];
}
if (item.xtype === 'datetimefield') {
_$2.defer(function () {
//@ts-ignore
scope.viewModel.set(item.param_name, moment(window.getServerTime()).format('YYYY-MM-DD HH:mm:ss'));
});
}
else if (item.xtype === 'datefield') {
_$2.defer(function () {
//@ts-ignore
scope.viewModel.set(item.param_name, moment(window.getServerTime()).format('YYYY-MM-DD'));
});
}
else {
scope.viewModel.set(item.param_name, '');
}
}
else {
// 没有组件类型,是个空占位符
vj.border = false;
}
if (item.param_name) {
vj.bind = {
value: '{' + item.param_name + '}'
};
_$2.set(newConfig.dataSource, 'params.' + item.param_name, '{' + item.param_name + '}');
_$2.set(dataSource, 'params.' + item.param_name, '{' + item.param_name + '}');
}
newRow_1 = (_a = item.wrap) !== null && _a !== void 0 ? _a : false;
currentRow_1.items.push(vj);
});
newConfig.tbar = {
xtype: 'form',
border: false,
items: conditionRows_1,
defaults: {
margin: '8 0 8 0'
},
};
console.log('newConfig', newConfig);
}
_$2.each(newConfig.columns, function (c) {
var renderer = c.renderer, formatter = c.formatter;
if (typeof renderer === 'string' && (_$2.startsWith(renderer, "scope.") ||
_$2.startsWith(renderer, "system."))) {
if (newConfig.$initParent) {
if (scope) {
var rendererFn = lookupFn(scope, renderer);
c.renderer = rendererFn.bind(scope);
}
}
}
if (c.dict) {
c.fix = ['system.getDict("' + c.dict + '")'];
if (c.editor && c.editor.xtype === 'combo') {
c.editor.fix = ['system.getDict("' + c.dict + '")'];
c.editor.typeAhead = true;
c.editor.triggerAction = 'all';
c.editor.selectOnFocus = false;
c.editor.listConfig = {
minWidth: 200
};
}
}
if (formatter === 'button') {
c.tdCls = 'td-btn';
if (!c.listeners) {
c.listeners = {};
}
c.listeners.click = function (sender, td, rowIdx, colIdx, event, record) {
if ($(event.target).is('input')) {
me.fireEvent('buttonclick', me, this, record);
}
};
}
else if (formatter === 'percentRenderer') {
c.tdCls = 'td-percent';
}
});
if (newConfig._mode === 'edit' || newConfig._mode === 'edit1' || newConfig._mode === 'edit2') {
// 强制为编辑模式
newConfig.selModel = {
type: 'spreadsheet',
columnSelect: true,
pruneRemoved: false,
extensible: 'y'
};
newConfig.plugins = __assign(__assign({}, newConfig.plugins), { clipboard: true, selectionreplicator: true });
if (newConfig._mode === 'edit2' || newConfig._mode === 'edit') {
_$2.set(newConfig, 'plugins.cellediting.clicksToEdit', 2);
}
else {
_$2.set(newConfig, 'plugins.cellediting.clicksToEdit', 1);
}
}
else if (newConfig._mode === 'checkbox' || newConfig._mode === 'check') {
// 强制为勾选模式
newConfig.selModel = {
type: 'checkboxmodel',
mode: 'MULTI',
};
}
else if (newConfig._mode === 'checkonly') {
newConfig.selModel = {
type: 'checkboxmodel',
mode: 'MULTI',
checkOnly: true,
};
}
else if (newConfig._mode === 'select') {
// 强制为选择模式
newConfig.selModel = {
selType: 'rowmodel',
mode: 'SINGLE',
};
if (typeof _$2.get(newConfig, 'plugins.cellediting.clicksToEdit') === 'number') {
_$2.set(newConfig, 'plugins.cellediting.clicksToEdit', 2);
}
}
initBehaviorEdit(newConfig);
initGridDialog(newConfig);
this.superclass.constructor.call(this, newConfig);
this.store.pageSize = newConfig.pageSize;
},
setData: function (value) {
var me = this;
me._setDataReal(value);
},
/**
* 添加行,并进入编辑状态
* @param record 新行的属性集
* @param editRowCol 要编辑的列序号,或 dataIndex 的名称
*/
appendEditRow: function (record, editRowCol) {
var records = this.getStore().add(record);
var recNew = records[0];
this.setSelection(records);
if (typeof editRowCol === 'string' && editRowCol) {
editRowCol = this.columns.findIndex(function (c) { return c.dataIndex === editRowCol; });
}
if (typeof editRowCol === 'number') {
var ce = this.findPlugin('cellediting');
this.editingPlugin = ce;
ce.startEdit(recNew, editRowCol);
}
},
beginEdit: function (record, editRowCol) {
if (typeof record === 'number') {
record = this.store.data.getAt(record);
}
if (record.isEntity === true) {
this.setSelection([record]);
if (typeof editRowCol === 'string' && editRowCol) {
editRowCol = this.columns.findIndex(function (c) { return c.dataIndex === editRowCol; });
}
if (typeof editRowCol === 'number') {
var ce = this.findPlugin('cellediting');
this.editingPlugin = ce;
ce.startEdit(record, editRowCol);
}
}
},
/**
* 移除行
* @param record 如果记录传空,就是当前选中的行
*/
removeEditRow: function (record) {
if (!record) {
record = this.selection;
}
if (!record) {
msg('请选中要删除的行');
return;
}
this.getStore().remove(record);
},
/**
* 获取全部原始数据
*/
getDataRows: function () {
return this.getStore().data.items.map(function (r) { return r.data; });
},
/**
* 获取全部原始数据, 不带 id/ 不带 origin
*/
getDataRowsOnlyData: function () {
return _$2.map(_$2.cloneDeep(this.getDataRows()), function (r) {
delete r.id;
delete r._origin;
return r;
});
},
rowMoveUp: function () {
var grid = this;
if (!grid.selection) {
msg('无法对多行进行移动');
return;
}
var record = grid.selection;
if (_$2.isArray(record)) {
record = record[0];
}
if (!record) {
msg('无法对多行进行移动');
return;
}
// const records = grid.selModel.getSelection()
// if (records.length !== 1) {
// msg('无法对多行进行移动')
// return
// }
//
// const [record] = records
var index = grid.store.indexOf(record);
if (index > 0) {
grid.store.removeAt(index);
grid.store.insert(index - 1, record);
grid.getView().refresh();
grid.selModel.select([record]);
}
},
rowMoveDown: function () {
var grid = this;
// const records = grid.selModel.getSelection()
// if (records.length !== 1) {
// msg('无法对多行进行移动')
// return
// }
if (!grid.selection) {
msg('无法对多行进行移动');
return;
}
var record = grid.selection;
if (_$2.isArray(record)) {
record = record[0];
}
if (!record) {
msg('无法对多行进行移动');
return;
}
var index = grid.store.indexOf(record);
if (index < grid.store.getCount() - 1) {
grid.store.removeAt(index);
grid.store.insert(index + 1, record);
grid.getView().refresh();
grid.selModel.select([record]);
}
},
getEditRecord: function () {
var _a, _b;
var me = this;
var editingPlugin = me.editingPlugin || me.ownerGrid.editingPlugin;
var rowIdx = (_b = (_a = editingPlugin === null || editingPlugin === void 0 ? void 0 : editingPlugin.activeEditor) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.rowIdx;
var record;
if (typeof rowIdx === 'undefined') {
record = me.getSelectionModel().getLastSelected();
}
else {
record = me.store.getAt(rowIdx);
}
return record;
},
getEditRow: function () {
var _a;
var me = this;
return (_a = me.getEditRecord()) === null || _a === void 0 ? void 0 : _a.data;
},
setEditRow: function (rowValues) {
var me = this;
var record = me.getEditRecord();
if (record) {
_$2.forOwn(rowValues, function (v, k) {
record.set(k, v);
});
}
},
_transform: function (data) {
// 无论是 grid._setDataReal 还是 stores.gridInvokeBuild 都会走这个函数,设值前都可以改变表格值
_$2.forEach(data, function (row) {
row._origin = _$2.clone(row);
});
},
_setDataReal: function (value) {
var me = this;
this._transform(value);
var storeOpt = {
fields: getFileds(this),
data: value,
};
if (this.groupField) {
storeOpt.groupField = this.groupField;
}
var store = new Ext.data.Store(storeOpt);
me.setStore(store);
},
setStore: function (store) {
var me = this;
if (_$2.isArray(store)) {
var value = store;
this._transform(value);
var storeOpt = {
fields: getFileds(this),
data: value,
};
if (this.groupField) {
storeOpt.groupField = this.groupField;
}
store = new Ext.data.Store(storeOpt);
}
me.superclass.setStore.call(this, store);
var reference = this.reference;
if (reference) {
var scope = lookupScope(this);
scope.viewModel.set(reference + '.ischanged', false);
scope.viewModel.set(reference + '.theid', null);
scope.viewModel.set(reference + '.theid2', null);
scope.viewModel.set(reference + '.theid3', null);
}
if (store) {
store.on({
add: function (store, records, index, eOpts) {
me._raiseChange(store, 'add');
},
remove: function (store, records, index, isMove, eOpts) {
me._raiseChange(store, 'remove');
},
datachanged: function (sender, opt) {
me._raiseChange(store, 'datachanged');
}
});
}
},
_raiseChange: function (store, type) {
var _a, _b;
var reference = this.reference;
if (reference && store) {
var ischanged = false;
if (store.getModifiedRecords().length > 0 ||
store.getNewRecords().length > 0 ||
store.getRemovedRecords().length > 0) {
ischanged = true;
}
else {
ischanged = false;
}
(_b = (_a = lookupScope(this)) === null || _a === void 0 ? void 0 : _a.viewModel) === null || _b === void 0 ? void 0 : _b.set(reference + '.ischanged', ischanged);
}
},
/**
* 轻量级刷新
*/
refreshData: function () {
var store = this.getStore();
if (store) {
store.reload();
}
},
/**
* 为表格强制设置焦点
* @param seq 顺序号
*/
focusRow: function (seq) {
this.setSelection(this.store.getAt(seq));
this.getView().focusRow(seq);
},
/**
* 重新载入数据(重新计算参数)
*/
reload: function (reloadParams) {
if (reloadParams === void 0) { reloadParams = {}; }
var me = this;
var config = me.config;
if (config.dataSourceCallbackFn) {
// 函数请求刷新
var scope_1 = lookupScope(this);
_$2.defer(function () {
me.setLoading(true);
});
config.dataSourceCallbackFn.call(scope_1, me, {
successCallback: function (value) {
me._setDataReal(value);
_$2.defer(function () {
me.setLoading(false);
});
// 自动选中第一行
var data = me.getStore().data;
if (data.length > 0) {
me.setSelection(data.items[0]);
}
me.fireEvent('dataLoadComplete', me, true, value);
},
failCallback: function (error) {
_$2.defer(function () {
me.setLoading(false);
});
me.fireEvent('dataLoadComplete', me, false, error);
}
});
return;
}
// if (this.store) {
// this.store.reload({aaaa: 1, bbbb: 2})
// }
var dataSource = config.dataSource;
var scope = lookupScope(me);
if (_$2.isPlainObject(dataSource) && !isDesignMode(scope, config)) {
gridInvokeBuild(scope, me, config, dataSource, reloadParams);
}
},
exportCurrentExcelClick: function () {
var _a;
var me = this;
var config = me.config;
var scope = lookupScope(me);
var excelFileName = config.excelFileName || scope.vjson.title || _$2.uniqueId("excel-");
if (excelFileName.endsWith(".xlsx")) {
excelFileName = excelFileName.split(".xlsx")[0];
}
excelFileName += ".xlsx";
var rowsAll = (_a = this.getStore().getData().items) === null || _a === void 0 ? void 0 : _a.map(function (r) { return r.data; });
var excelData = me.makeExcelData(rowsAll);
LAY_EXCEL.exportExcel(excelData, excelFileName, 'xlsx');
},
/**
* excel 导出
* excelExportParams 导出参数
* isContinue 是否继续导出
*/
exportExcelClick: function (excelExportParams, isContinue) {
if (isContinue === void 0) { isContinue = false; }
var me = this;
var config = me.config;
excelExportParams.isExcelExport = true;
var scope = lookupScope(me);
var dataSource = config.dataSource;
var ep = function () {
scope.setLoading(true);
gridInvokeBuild(scope, me, config, dataSource, excelExportParams, true, function (responseData) {
var _a, _b, _c, _d;
var page = parseInt((_a = responseData.pagination) === null || _a === void 0 ? void 0 : _a.current) || me.exportExcelCurrentPage || 1;
var size = parseInt((_b = responseData.pagination) === null || _b === void 0 ? void 0 : _b.size) || me.exportExcelPageSize;
var total = parseInt((_c = responseData.pagination) === null || _c === void 0 ? void 0 : _c.total) || ((_d = responseData.data) === null || _d === void 0 ? void 0 : _d.length) || 0;
me.exportExcelCurrentPage = page;
me.exportExcelPageSize = size;
me.exportExcelTotal = total;
var excelFileName = config.excelFileName || scope.vjson.title || _$2.uniqueId("excel-");
if (excelFileName.endsWith(".xlsx")) {
excelFileName = excelFileName.split(".xlsx")[0];
}
var pageExcelData = me.makeExcelData(responseData.data);
excelFileName += "(第" + me.exportExcelCurrentPage + "页,共" + Math.ceil(total / size) + "页、" + total + "条)";
excelFileName += ".xlsx";
LAY_EXCEL.exportExcel(pageExcelData, excelFileName, 'xlsx');
scope.setLoading(false);
if (page < total / size) {
page++;
me.exportExcelCurrentPage = page;
if (isContinue === true) {
excelExportParams.exportExcelCurrentPage = page;
ep();
}
}
});
};
ep();
},
exportBigExcelClick: function () {
var _a;
var me = this;
if (!((_a = me.dbInfo) === null || _a === void 0 ? void 0 : _a.jdbcurl) || !me.exportDataSql) {
showErrorDialog('当前表格不支持大批量导出');
return;
}
var config = me.config;
var scope = lookupScope(me);
var excelFileName = config.excelFileName || scope.vjson.title || _$2.uniqueId("excel-");
var head = [];
var dict = {};
_$2.forEach(me.columns, function (column) {
if (column.isHidden())
return;
if (!column.dataIndex)
return;
if (!column.text)
return;
head.push({ field: column.dataIndex, name: column.text });
if (column.dictForExcel) {
dict[column.dataIndex] = column.dictForExcel;
}
});
// 判断是否需要解密
if (me.dbInfo.jdbcurl.indexOf("jdbc") < 0) {
me.dbInfo.jdbcurl = hexToString(me.dbInfo.jdbcurl);
me.dbInfo.password = hexToString(me.dbInfo.password);
me.dbInfo.username = hexToString(me.dbInfo.username);
}
scope.setLoading(true);
Ext.Ajax.request({
timeout: 15000,
url: window["EXPORT_DATA_HOST"],
method: "POST",
jsonData: {
file: excelFileName,
dbInfo: me.dbInfo,
exportDataSql: me.exportDataSql,
exportDataSqlParams: me.exportDataSqlParams,
head: head,
dict: dict,
},
}).then(function () {
scope.setLoading(false);
msg('请求成功');
}).catch(function () {
scope.setLoading(false);
showErrorDialog('请求失败,请确认是否已安装客户端');
});
},
makeExcelData: function (jsonData) {
var me = this;
me.fireEvent('onExcelDataLoadCompleted', me, jsonData);
if (!Array.isArray(jsonData) || jsonData.length === 0) {
return;
}
var data = [];
// 获取表格的列定义
var headerTextArr = [];
var headers = [];
for (var i = 0; i < me.headerCt.getGridColumns().length; i++) {
var header = me.headerCt.getGridColumns()[i];
if (!header.isHidden()) {
var textStr = _$2.trim(header.text);
var dataIndexStr = _$2.trim(header.dataIndex);
if (dataIndexStr) {
if (textStr === '') {
headerTextArr.push(dataIndexStr);
}
else {
headerTextArr.push(textStr);
}
headers.push(header);
}
}
}
if (headers.length === 0) {
return;
}
data.push(headerTextArr);
for (var i = 0; i < jsonData.length; i++) {
var dataRow = jsonData[i];
var row = [];
for (var j = 0; j < headers.length; j++) {
var key = headers[j].dataIndex;
var value = dataRow[key];
if (!value && value !== 0) {
value = '';
}
var oValue = value;
// todo 导出处理字典日期等数据,如果有特殊的单元格渲染也可能出现导出的数据有特殊标记需要特殊处理一下
if (typeof headers[j].renderer === 'function' && (!headers[j].config.formatter)) {
try {
value = headers[j].renderer(value);
if (!value && value !== 0) {
value = oValue;
}
}
catch (e) {
value = oValue;
}
}
row.push(value);
}
data.push(row);
}
return data;
},
initComponent: function () {
var _this = this;
var _a;
var me = this;
var config = me.config;
var scope = lookupScope(this);
if (isDesignMode(scope, config)) {
this.superclass.initComponent.call(this);
return;
}
// 转换 dataSource 属性
convertDataSource$1(me, scope, config);
this.on({
afterrender: function (sender) {
var me = this;
var config = this.config;
var dataSource = config.dataSource;
if (config.autoLoad) {
if (config.dataSourceCallbackFn) {
me.reload();
}
else if (_$2.isPlainObject(dataSource)) {
me.reload();
}
}
if (config.contextMenu === true && _$2.isArray(config.tbar)) {
var vm = this.lookupViewModel();
this.contextMenu = this.add(new Ext.menu.Menu({
viewModel: vm,
items: _$2.map(config.tbar, function (item) {
var menuItem = __assign({}, item);
if (menuItem.xtype === 'button') {
delete menuItem.xtype;
}
return menuItem;
})
}));
}
else if (_$2.isPlainObject(config.contextMenu)) {
this.contextMenu = this.add(config.contextMenu);
}
var $dom = $(sender.el.dom);
$dom.on('keydown', function (e) {
me.fireEvent('keydown', me, e);
}).on('keyup', function (e) {
me.fireEvent('keyup', me, e);
});
// 默认显示提示
if (this.cellTip) {
this.tip = Ext.create('Ext.tip.ToolTip', {
target: this.el,
delegate: '.x-grid-cell-inner',
trackMouse: true,
ancor: 'top',
style: 'background-color: #0D6EFD;',
listeners: {
beforeshow: function (tip) {
var tipText = (tip.triggerElement.innerText || tip.triggerElement.textContent);
if (Ext.isEmpty(tipText) || Ext.isEmpty(tipText.trim())) {
return false;
}
tip.update(tipText);
}
}
});
}
},
itemcontextmenu: function (view, rec, node, index, e) {
if (this.contextMenu) {
e.stopEvent();
this.contextMenu.show().setLocalXY(e.getXY());
return false;
}
},
// columnmove(sender, column, fromIndex, toIndex, eOpts) {
// this.setColumnConfigCache()
// },
// columnhide(sender, column, eOpts) {
// this.setColumnConfigCache()
// },
// columnshow(sender, column, eOpts) {
// this.setColumnConfigCache()
// },
// columnresize(sender, column, width, eOpts) {
// this.setColumnConfigCache()
// },
destory: function () {
},
selectionchange: function (sender, param) {
var record = undefined;
if (_$2.isArray(param)) {
record = param[0];
}
else if (_$2.isObject(param)) {
record = _$2.get(param, 'endCell.record');
}
itemselectFun(this, sender, record);
},
itemclick: function (sender, record) {
itemselectFun(this, sender, record);
},
show: function (sender) {
if (sender.__suspendReload) {
sender.__suspendReload = false;
sender.reload();
}
}
});
_$2.defer(function () {
var ce = _this.findPlugin('cellediting');
ce.on({
beforeedit: function (editor, context, eOpts) {
me.fireEvent('editbefore', me, editor, context, eOpts);
},
canceledit: function (editor, context, eOpts) {
me.fireEvent('editcancel', me, editor, context, eOpts);
},
edit: function (editor, context, eOpts) {
me.fireEvent('editfinish', me, editor, context, eOpts);
},
validateedit: function (editor, context, eOpts) {
me.fireEvent('editvalidate', me, editor, context, eOpts);
},
});
});
var itemselectFun = _$2.debounce(function (me, sender, record) {
var reference = me.reference;
var scope = lookupScope(me);
var theid = _$2.get(config, 'behavior.theid');
if (theid && reference) {
if (!record) {
scope.viewModel.set(reference + '.theid', null);
}
else {
scope.viewModel.set(reference + '.theid', record.get(theid));
}
}
var theid2 = _$2.get(config, 'behavior.theid2');
if (theid2 && reference) {
if (!record) {
scope.viewModel.set(reference + '.theid2', null);
}
else {
scope.viewModel.set(reference + '.theid2', record.get(theid2));
}
}
var theid3 = _$2.get(config, 'behavior.theid3');
if (theid3 && reference) {
if (!record) {
scope.viewModel.set(reference + '.theid3', null);
}
else {
scope.viewModel.set(reference + '.theid3', record.get(theid3));
}
}
me.fireEvent('itemselect', sender, record);
}, 50);
if ((_a = this.store) === null || _a === void 0 ? void 0 : _a.proxy) {
// 为 stores.proxy.buildRequest 做准备
this.store.proxy.$owner = this;
}
var selectToReload = _$2.get(config, 'behavior.selectToReload');
if (selectToReload) {
// 点击后触发某个目标表格刷新
this.on({
itemselect: function (sender) {
if (_$2.isArray(selectToReload)) {
_$2.forEach(selectToReload, function (ref) {
if (ref) {
var ctlTarget = scope.refs[ref];
if (ctlTarget && typeof ctlTarget.reload === 'function') {
if (ctlTarget.isVisible()) {
ctlTarget.reload();
}
else {
ctlTarget.__suspendReload = true;
}
}
}
});
}
else if (_$2.isString(selectToReload)) {
var ctlTarget = scope.refs[selectToReload];
if (ctlTarget && typeof ctlTarget.reload === 'function') {
ctlTarget.reload();
}
}
}
});
}
this.superclass.initComponent.call(this);
},
// 生成列自定义的缓存key
makeColumnConfigCacheKey: function (config) {
var _a, _b, _c, _d, _e, _f;
var scope = ((_a = config.$initParent) === null || _a === void 0 ? void 0 : _a.yvanScope) || ((_c = (_b = config.$initParent) === null || _b === void 0 ? void 0 : _b.lookupReferenceHolder()) === null || _c === void 0 ? void 0 : _c.yvanScope) || ((_d = config.$vmParent) === null || _d === void 0 ? void 0 : _d.yvanScope) || ((_f = (_e = config.$vmParent) === null || _e === void 0 ? void 0 : _e._parent) === null || _f === void 0 ? void 0 : _f.yvanScope);
var key = "gridColumnCache-" + scope.scopeKey + "-";
if (config.reference) {
key += config.reference;
}
else {
var subKey = "";
for (var i = 0; i < config.columns.length; i++) {
var column = config.columns[i];
if (column.dataIndex) {
subKey += column.dataIndex;
}
}
key += subKey;
}
return key;
},
getColumnConfigCache: function () {
var key = this.columnConfigCacheKey;
var dataStr = localStorage.getItem(key);
if (dataStr) {
return JSON.parse(dataStr);
}
return "";
},
setColumnConfigCache: function () {
var key = this.columnConfigCacheKey;
var cacheData = [];
var columns = this.headerCt.getGridColumns();
var index = 0;
for (var i = 0; i < columns.length; i++) {
var column = columns[i];
if (column.dataIndex) {
cacheData.push({
dataIndex: column.dataIndex,
width: column.width,
hidden: column.hidden,
locked: column.locked,
index: index
});
index++;
}
}
localStorage.setItem(key, JSON.stringify(cacheData));
},
autoSizeColumns: function (sender) {
var grid = sender ? sender.up('grid') : this;
// const columns = grid.columns;
// for (let i = 0; i < columns.length; i++) {
// const column = columns[i];
// grid.getView().autoSizeColumn(column);
// column.setWidth(column.getWidth() + 5);
// }
for (var i = 1; i < grid.headerCt.getColumnCount(); i++) {
grid.headerCt.getGridColumns()[i].autoSize(i);
grid.headerCt.getGridColumns()[i].setWidth(grid.headerCt.getGridColumns()[i].getWidth() + 15);
}
},
clearFilter: function (sender) {
var grid = sender.up('grid');
grid.filters.clearFilters();
grid.getStore().sorters.removeAll();
// grid.getStore().reload()
},
saveGridUIConfig: function (sender) {
var grid = sender.up('grid');
grid.setColumnConfigCache();
msg('保存设置成功!');
},
clearGridUIConfig: function (sender) {
var grid = sender.up('grid');
var key = grid.columnConfigCacheKey;
localStorage.setItem(key, "");
msg('清空设置成功,重新打开后生效!');
},
setLoading: function (value) {
if (value) {
this.mask('读取中');
}
else {
this.unmask();
}
},
exportExcel: function (sender) {
var _a, _b;
var rect = sender.btnEl.dom.getBoundingClientRect();
var scope = lookupScope(this);
var grid = sender.up('grid');
var menuItems = [];
var topOffset = 0;
if (((_a = grid === null || grid === void 0 ? void 0 : grid.dataSource) === null || _a === void 0 ? void 0 : _a.method) === 'invoke' || ((_b = grid === null || grid === void 0 ? void 0 : grid.dataSource) === null || _b === void 0 ? void 0 : _b.sqlId)) {
menuItems.push({
text: '大批量导出 (需要客户端支持!)',
iconCls: 'x-fa fa-download',
listeners: {
click: function (sender, value) {
// @ts-ignore
YvanUI.confirm('大批量数据导出会占用大量服务器资源和带宽资源,您真的要导出吗?')
.then(function (res) {
grid.exportBigExcelClick();
});
}
}
});
menuItems.push('-');
topOffset += 30;
}
menuItems.push({
text: '导出当前数据',
iconCls: 'x-fa fa-download',
listeners: {
click: function (sender, value) {
grid.exportCurrentExcelClick();
}
}
});
topOffset += 30;
if (grid === null || grid === void 0 ? void 0 : grid.dataSource) {
menuItems.push({
xtype: "textfield",
fieldLabel: '当前导出页',
maskRe: /[0-9]/,
value: grid.exportExcelCurrentPage,
listeners: {
render: function (sender) {
grid.exportExcelCurrentPageCmp = sender;
},
change: function (sender, value) {
var v = parseInt(value);
if (isNaN(v) || v === 0) {
window['system'].msg("页码不能为0");
v = 1;
sender.setValue(v);
}
var size = parseInt(grid.exportExcelPageSize);
var total = parseInt(grid.exportExcelTotal);
if (v > total / size) {
v = parseInt(total / size + "");
}
grid.exportExcelCurrentPage = v + "";
}
}
}, {
xtype: "textfield",
fieldLabel: '导出页大小',
maskRe: /[0-9]/,
value: grid.exportExcelPageSize,
listeners: {
render: function (sender) {
grid.exportExcelPageSizeCmp = sender;
},
change: function (sender, value) {
var v = parseInt(value);
if (isNaN(v) || v === 0) {
window['system'].msg("导出页大小不能为0");
v = defaultGrid.exportExcelPageSize;
sender.setValue(v);
}
if (v > 10000) {
window['system'].msg("导出页大小不能大于10000");
v = 10000;
sender.setValue(v);
}
var page = parseInt(grid.exportExcelCurrentPage);
var total = parseInt(grid.exportExcelTotal);
if (page > total / v) {
page = parseInt(total / v + "") + 1;
grid.exportExcelCurrentPageCmp.setValue(page);
}
grid.exportExcelPageSize = v + "";
}
}
}, {
xtype: "textfield",
fieldLabel: '总条数',
value: grid.exportExcelTotal,
readOnly: true
}, {
text: '导出',
iconCls: 'x-fa fa-download',
listeners: {
click: function (sender, value) {
grid.exportExcelClick({
exportExcelPageSize: grid.exportExcelPageSize,
exportExcelCurrentPage: grid.exportExcelCurrentPage
});
}
}
}, {
text: '连续导出',
iconCls: 'x-fa fa-download',
listeners: {
click: function (sender, value) {
grid.exportExcelClick({
exportExcelPageSize: grid.exportExcelPageSize,
exportExcelCurrentPage: grid.exportExcelCurrentPage
}, true);
}
}
});
topOffset += 150;
}
var treeMenu = new Ext.menu.Menu({
xtype: 'menu',
floated: false,
width: 300,
docked: 'left',
items: menuItems
});
treeMenu.showAt(rect.left, rect.top - topOffset);
// for (let i = 1; i < grid.headerCt.getColumnCount(); i++) {
// grid.headerCt.getGridColumns()[i].autoSize(i);
// grid.headerCt.getGridColumns()[i].setWidth(grid.headerCt.getGridColumns()[i].getWidth() + 15);
// }
},
/**
* 获取表格编辑的行数据
*/
getGridEditRows: function () {
var grid = this;
var store = grid.getStore();
var rows = [];
var modifyRows = [];
var newRows = [];
var err = "";
var records = store.getModifiedRecords();
var newRecords = store.getNewRecords();
var removeRecords = [];
_$2.forEach(store.getRemovedRecords(), function (row) {
removeRecords.push(row.data);
});
_$2.forEach(records, function (record) {
var colums = grid.columns;
var errFunc = undefined;
_$2.forEach(colums, function (col) {
var name = col.dataIndex;
var value = record.data[name];
var colIndex = col.getIndex(); //获得列号
var rowIndex = store.indexOfId(record.id); //获得行号
var editor = col.getEditor(); //使用的编辑器
var tmpErrFunc = function () {
var text = col.text || col.name;
msg(text + ' 校验失败, 请确保输入的数据正确');
grid.findPlugin('cellediting').startEdit(rowIndex, col); //如果不通过激活当前编辑状态
};
if (editor && !editor.allowBlank && isEmpty(value)) {
errFunc = tmpErrFunc;
return false;
}
if (editor && !isEmpty(value) && !editor.validateValue(value)) {
errFunc = tmpErrFunc;
return false;
}
});
if (typeof errFunc === 'function') {
err = "1";
_$2.remove(rows, function (n) {
return true;
});
//@ts-ignore
errFunc();
// Ext.Msg.alert('提示', '请确保输入的数据正确', errFunc)
return false;
}
else {
if (_$2.findIndex(newRecords, function (item) {
return item === record;
}) >= 0) {
newRows.push(record.data);
}
else {
modifyRows.push(record.data);
}
rows.push(record.data);
}
});
return {
rows: rows,
newRows: newRows,
modifyRows: modifyRows,
removeRecords: removeRecords,
err: err
};
}
// reload() {
// dataSourceReload(this)
// },
});
}
/**
* 获取 columns 中所有的 dataIndex
*/
function getFileds(newConfig) {
var fields = [];
_$2.forEach(newConfig.columns, function (c) {
if (c.dataIndex) {
fields.push(c.dataIndex);
}
});
return fields;
}
function convertDataSource$1(sender, scope, newConfig) {
if (typeof newConfig.store !== 'undefined') {
// 有 store 属性的情况下,不做任何事
return;
}
if (typeof newConfig.dataSource === 'undefined') {
// 没有定义 dataSource 的情况下,不做任何事
return;
}
if (_$2.isArray(newConfig.data)) {
// 有 data 属性赋值的情况下
newConfig.store = {
fields: getFileds(newConfig),
data: newConfig.data
};
delete newConfig.data;
return;
}
var dataSource = newConfig.dataSource;
if (typeof dataSource === 'string') {
// dataSource 是字符串的情况下,找到成员函数
dataSource = lookupFn(scope, dataSource);
}
if (typeof dataSource === 'function') {
// dataSource 是函数的情况下,在 afterrender 之后进行回调
newConfig.store = new Ext.data.Store({
fields: getFileds(newConfig),
// data: [],
autoLoad: true,
proxy: {
type: 'memory',
data: [],
}
});
newConfig.dataSourceCallbackFn = dataSource;
return;
}
// throw new TypeError('无法识别的调用方法')
}
function initTextfield () {
var cc = Ext.form.field.Text.prototype.constructor;
var initComponent = Ext.form.field.Text.prototype.initComponent;
Ext.form.field.Text.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制属性
triggers: {
clear: {
weight: -1,
cls: Ext.baseCSSPrefix + 'form-clear-trigger',
hidden: true,
handler: 'onClearClick',
},
}
}, baseConfig(config, 'col-item'), config, text);
if (config === null || config === void 0 ? void 0 : config.nextFocus) {
newConfig.enableKeyEvents = true;
}
cc.call(this, newConfig);
},
/**
* 清空所有值
*/
onClearClick: function (sender, e) {
var me = this;
me.setValue('');
},
/**
* 尝试获取下一个要获取焦点的控件
*/
_raiseNextFocus: function (sender) {
var config = sender.config;
var scope = lookupScope(sender);
if (typeof config.nextFocus === 'function') {
config.nextFocus(sender);
}
else if (typeof config.nextFocus === 'string' && _$2.size(config.nextFocus) > 0) {
if (_$2.startsWith(config.nextFocus, 'scope.')) {
var fn = lookupFn(scope, config.nextFocus);
if (typeof fn === 'function') {
var nextCtlReference = fn(sender);
if (typeof nextCtlReference === 'string' && _$2.size(nextCtlReference) > 0) {
var ctl = scope === null || scope === void 0 ? void 0 : scope.refs[nextCtlReference];
if (ctl) {
if (typeof ctl.focus2 === 'function') {
ctl.focus2();
}
else {
ctl.focus();
}
}
}
}
}
else {
var ctl = scope === null || scope === void 0 ? void 0 : scope.refs[config.nextFocus];
if (ctl) {
if (typeof ctl.focus2 === 'function') {
ctl.focus2();
}
else {
ctl.focus();
}
}
}
}
},
initComponent: function () {
/**
* 改变必填项之前加星号
*/
if (this.config.readOnly !== true && (this.allowBlank === false || this.validateBlank === true)) {
// this.beforeLabelTextTpl = [
// '*'
// ];
this.afterLabelTextTpl = [
'*'
];
}
var me = this;
this.on({
change: function (sender, newVal) {
var hideTrigger = sender.hideTrigger, disabled = sender.disabled, readOnly = sender.readOnly, hideClear = sender.hideClear;
if (hideTrigger || disabled || readOnly || hideClear) {
// 禁用、隐藏、只读、隐藏清空状态下,不需要显示清空按钮
return;
}
var value = newVal;
if (value) {
me.getTrigger('clear').show();
me.updateLayout();
}
else {
me.getTrigger('clear').hide();
me.updateLayout();
}
},
afterrender: function (sender) {
var _this = this;
var _a;
if ((_a = sender.inputEl) === null || _a === void 0 ? void 0 : _a.dom) {
sender.inputEl.dom.setAttribute('spellcheck', "false");
$$2(sender.inputEl.dom).on('click', function (e) {
sender.fireEvent('click', _this, e);
});
$$2(sender.inputEl.dom).on('keydown', function (e) {
var _a, _b, _c, _d;
// 表格内编辑器,按上下键时,可以切换到下一行/上一行 进入编辑
if (e.code === "ArrowDown" || e.code === 'ArrowUp') {
if (sender.isExpanded === true) {
// 弹开下拉框的基础上,不干预上下选择
return;
}
if (((_a = sender.ownerCt) === null || _a === void 0 ? void 0 : _a.xtype) === 'celleditor') {
var grid = sender.ownerCt.up('grid');
var editingPlugin = grid.editingPlugin || grid.ownerGrid.editingPlugin;
if (editingPlugin) {
var rowIdx = (_c = (_b = editingPlugin === null || editingPlugin === void 0 ? void 0 : editingPlugin.activeEditor) === null || _b === void 0 ? void 0 : _b.context) === null || _c === void 0 ? void 0 : _c.rowIdx;
var column = (_d = editingPlugin === null || editingPlugin === void 0 ? void 0 : editingPlugin.activeEditor) === null || _d === void 0 ? void 0 : _d.column;
if (typeof rowIdx !== 'undefined' && typeof column !== 'undefined') {
// editingPlugin
var targetRecord = void 0;
if (e.code === 'ArrowDown') {
targetRecord = grid.store.data.getAt(rowIdx + 1);
}
else {
targetRecord = grid.store.data.getAt(rowIdx - 1);
}
if (targetRecord) {
grid.setSelection([targetRecord]);
editingPlugin.startEdit(targetRecord, column);
}
e.stopPropagation();
e.preventDefault();
}
}
}
}
});
}
var config = sender.config;
if (config.ff && config.ff > 0) {
setTimeout(function () {
if (typeof sender.focus2 === 'function') {
sender.focus2();
}
else {
sender.focus();
}
}, config.ff);
}
}
});
var config = this.config;
if (config === null || config === void 0 ? void 0 : config.nextFocus) {
this.on({
keyup: function (sender, e) {
if ([10, 13, 20, 40].includes(e.keyCode)) {
sender._raiseNextFocus(sender);
}
}
});
}
var that = this;
this.on({
keyup: function (sender, e, eOpts) {
if (![10, 13, 20, 40].includes(e.keyCode)) {
return;
}
that.keydown_fun_item(sender, e, eOpts);
}
});
initComponent.call(this);
},
keydown_fun_item: _$2.debounce(function (sender, event, eOpts) {
var that = sender;
if ([10, 13, 20, 40].includes(event.keyCode)) {
// 获取读码器读取的内容,最好不要从 viewModel 中取值,而是从 sender.rawValue 中取值
var value = _$2.trim(sender.rawValue);
var r = that.fireEvent('scancode', that, value, event);
if (r === 'OK') {
// 停止事件的默认处理程序,停止事件的冒泡
// event.stopEvent();
event.preventDefault();
event.stopPropagation();
}
}
}, 100)
});
}
function initTbFill () {
/**
*
*/
var ct = Ext.toolbar.Fill.prototype.constructor;
Ext.toolbar.Fill.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({}, config, baseConfig(config, "col-item"), tbfill);
ct.call(this, newConfig);
}
});
}
function initTbSeparator () {
/**
*
*/
var ct = Ext.toolbar.Separator.prototype.constructor;
Ext.toolbar.Separator.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({}, config, baseConfig(config, "col-item"), tbseparator);
ct.call(this, newConfig);
}
});
}
function initToolbar () {
/**
*
*/
var ct = Ext.toolbar.Toolbar.prototype.constructor;
Ext.toolbar.Toolbar.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制性属性
}, baseConfig(config, 'cols-container'), config, toolbar);
ct.call(this, newConfig);
}
});
initTbFill();
initTbSeparator();
}
function initSplitter () {
var ct = Ext.resizer.Splitter.prototype.constructor;
Ext.resizer.Splitter.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({}, config, baseConfig(config, "row-item"), splitter);
ct.call(this, newConfig);
}
});
}
/**
* 通用 dataSource 解析,
* Tree/Combo/Grid/PageList ... 都会从这里解析
*/
function dataSourceReload(ctl, extraParam, _successCb, successCallback, failCallback) {
var config = ctl.config;
return new Promise(function (resolve, reject) {
if (!config.dataSource) {
// 没有设置数据源,直接置空
return Promise.resolve();
}
var option = {
extraParam: extraParam,
_successCb: _successCb,
successCallback: function (value) {
if (typeof successCallback === "function") {
successCallback(value);
}
else {
ctl.setData(value);
}
ctl.fireEvent('dataLoadComplete', ctl, true, value);
ctl.setLoading(false);
resolve(value);
},
failCallback: function (error) {
if (typeof failCallback === "function") {
failCallback(error);
}
ctl.fireEvent('dataLoadComplete', ctl, false);
ctl.setLoading(false);
reject(error);
}
};
// 请求前要求确认一下
var isCanceled = false;
ctl.fireEvent('dataBeforeLoad', ctl, __assign({ cancel: function () {
isCanceled = true;
} }, option));
if (!isCanceled) {
// 请求没有被取消
// 调用异步接口返回 Promise
return _innerReload(ctl, option);
}
return reject();
});
}
function _innerReload(ctl, option) {
var config = ctl.config;
ctl.setLoading(true);
var scope = lookupScope(ctl);
var dataSource = config.dataSource;
if (typeof dataSource == 'string') {
dataSource = lookupFn(scope, config.dataSource);
}
if (typeof dataSource === 'function') {
// @ts-ignore
dataSource.call(scope, ctl, option);
return;
}
else if (typeof (dataSource === null || dataSource === void 0 ? void 0 : dataSource.url) === 'string' || typeof (dataSource === null || dataSource === void 0 ? void 0 : dataSource.sqlId) === 'string') {
if (!ajax.func) {
console.error("没有配置 ajax");
return;
}
var params_1 = {};
var sortModel = null;
var filterModel = null;
if (option.extraParam && option.extraParam.filterModel) {
filterModel = option.extraParam.filterModel;
}
if (option.extraParam && option.extraParam.sortModel) {
sortModel = option.extraParam.sortModel;
}
_$2.forOwn(option.extraParam, function (v, key) {
if (key != "filterModel" && key != "sortModel") {
if (typeof v === 'function') {
params_1[key] = v();
}
else {
params_1[key] = v;
}
}
});
var ds = dataSource;
_$2.forOwn(ds.params, function (v, key) {
if (typeof v === 'function') {
params_1[key] = v();
}
else {
params_1[key] = v;
}
});
if (typeof (dataSource === null || dataSource === void 0 ? void 0 : dataSource.url) === 'string') {
// @ts-ignore
ajax.func({
method: dataSource.method,
url: ds.url,
data: params_1,
filterModel: filterModel,
sortModel: sortModel,
}).then(function (res) {
if (res.success) {
option.successCallback(res.data);
}
else {
option.failCallback(res.msg);
}
}).catch(function (e) {
option.failCallback(e);
});
}
else if (typeof (dataSource === null || dataSource === void 0 ? void 0 : dataSource.sqlId) === 'string') {
var ds_1 = ctl.dataSource;
// @ts-ignore
Extend.ajax.func({
url: ds_1.sqlId,
data: params_1,
db: ds_1.db,
method: 'sql',
filterModel: filterModel,
sortModel: sortModel,
}).then(function (res) {
if (res.success) {
option.successCallback(res.data);
}
else {
option.failCallback(res.msg);
}
}).catch(function (e) {
option.failCallback(e);
}).finally(function () {
ctl.loading = false;
});
return;
}
else {
console.error("非法的 dataSource", ctl.dataSource);
debugger;
throw new Error("非法的 dataSource");
}
}
}
function initCombo () {
var cc = Ext.form.field.ComboBox.prototype.constructor;
var _a = Ext.form.field.ComboBox.prototype, initComponent = _a.initComponent, setData = _a.setData, setStore = _a.setStore;
Ext.form.field.ComboBox.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制性属性
}, baseConfig(config, 'col-item'), config, combo);
if (typeof config.dict === 'string') {
window['yvanLib'].system.getDict(config.dict)(this, newConfig);
}
else if (typeof newConfig.store == 'undefined') {
if (_$2.isArray(newConfig.data)) {
// ExtJS 无法直接接受数组模式
newConfig.store = {
fields: [newConfig.valueField, newConfig.displayField],
data: newConfig.data
};
delete newConfig.data;
}
else if (typeof newConfig.data !== 'object') {
newConfig.store = {
fields: [newConfig.valueField, newConfig.displayField],
data: []
};
delete newConfig.data;
}
}
cc.call(this, newConfig);
},
setDict: function (bizKey) {
window['yvanLib'].system.getDict(bizKey)(this, this.config);
this.dict = bizKey;
},
getDict: function () {
return this.dict;
},
setData: function (value) {
if (!value) {
return;
}
var config = value.config;
if (!this.store) {
this.store = new Ext.data.Store({
fields: [config.valueField, config.displayField],
data: value
});
}
else {
this.store.getProxy().setData(value);
this.store.load();
}
},
setLoading: function (value) {
if (value) {
if (!this.loadMask) {
this.loadMask = new Ext.LoadMask(this, { msg: "loading..." });
}
}
else {
if (this.loadMask) {
this.loadMask.destroy();
delete this.loadMask;
}
}
},
reload: function () {
dataSourceReload(this);
},
initComponent: function () {
var that = this;
var toggle = function (e) {
var readOnly = that.readOnly, disabled = that.disabled;
if (readOnly || disabled) {
return;
}
if ($(e.target).is('.x-form-trigger')) {
return;
}
// 点击后下拉
if (that.isExpanded) {
that.collapse();
}
else {
that.expand();
that.doQuery(that.allQuery, true);
}
};
this.on({
afterrender: function (sender) {
var config = this.config;
if (config.dataSource && config.autoLoad) {
dataSourceReload(this);
}
// 点击后下拉
$(this.el.dom).on('click', toggle.bind(this));
},
focusenter: function (sender, event, opt) {
var _a;
if (((_a = sender.ownerCt) === null || _a === void 0 ? void 0 : _a.xtype) === 'celleditor') {
// 表格内编辑框,获取焦点后自动弹开
toggle.call(this, event);
}
},
destory: function () {
$(this.el.dom).off('click', toggle.bind(this));
},
beforequery: function (context) {
var cancel = context.cancel, forceAll = context.forceAll, lastQuery = context.lastQuery, query = context.query, rawQuery = context.rawQuery, combo = context.combo;
// console.log('beforequery', query)
if (!forceAll && query) {
combo.store.clearFilter();
combo.store.filterBy(function (record, id) {
var text = record.get(combo.displayField);
// 用拼音筛选的方式
return keywordFilter(query, text, id);
});
combo.expand();
return false;
}
combo.store.clearFilter();
combo.expand();
return false;
},
});
initComponent.call(this);
},
focus2: function () {
this.focus();
var that = this;
_$2.defer(function () {
if (that.isExpanded) {
that.collapse();
}
else {
that.expand();
that.doQuery(that.allQuery, true);
}
});
}
});
}
/**
xtype: 'tagfield',
displayField: 'show',
valueField: 'id',
queryMode: 'local',
filterPickList: true,
store: {
fields: ['id', 'show'],
data: [
{id: 0, show: 'Battlestar Galactica'},
{id: 1, show: 'Doctor Who'},
{id: 2, show: 'Farscape'},
{id: 3, show: 'Firefly'},
{id: 4, show: 'Star Trek'},
{id: 5, show: 'Star Wars: Christmas Special'}
]
}
*/
function initTag () {
var cc = Ext.form.field.Tag.prototype.constructor;
var _a = Ext.form.field.Tag.prototype, initComponent = _a.initComponent, setData = _a.setData, setStore = _a.setStore;
Ext.form.field.Tag.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制性属性
}, baseConfig(config, 'col-item'), config, tagfield);
if (typeof config.dict === 'string') {
window['yvanLib'].system.getDict(config.dict)(this, newConfig);
}
else if (typeof newConfig.store == 'undefined') {
if (_$2.isArray(newConfig.data)) {
// ExtJS 无法直接接受数组模式
newConfig.store = {
fields: [newConfig.valueField, newConfig.displayField],
data: newConfig.data
};
delete newConfig.data;
}
else if (typeof newConfig.data !== 'object') {
newConfig.store = {
fields: [newConfig.valueField, newConfig.displayField],
data: []
};
delete newConfig.data;
}
}
cc.call(this, newConfig);
},
setDict: function (bizKey) {
window['yvanLib'].system.getDict(bizKey)(this, this.config);
this.dict = bizKey;
},
getDict: function () {
return this.dict;
},
setData: function (value) {
if (!value) {
return;
}
var config = value.config;
if (!this.store) {
this.store = new Ext.data.Store({
fields: [config.valueField, config.displayField],
data: value
});
}
else {
this.store.getProxy().setData(value);
this.store.load();
}
},
setLoading: function (value) {
if (value) {
if (!this.loadMask) {
this.loadMask = new Ext.LoadMask(this, { msg: "loading..." });
}
}
else {
if (this.loadMask) {
this.loadMask.destroy();
delete this.loadMask;
}
}
},
reload: function () {
dataSourceReload(this);
},
initComponent: function () {
var that = this;
var toggle = function (e) {
var readOnly = that.readOnly, disabled = that.disabled;
if (readOnly || disabled) {
return;
}
if ($(e.target).is('.x-form-trigger')) {
return;
}
// 点击后下拉
if (that.isExpanded) {
that.collapse();
}
else {
that.expand();
that.doQuery(that.allQuery, true);
}
};
this.on({
afterrender: function (sender) {
var config = this.config;
if (config.dataSource && config.autoLoad) {
dataSourceReload(this);
}
// 点击后下拉
$(this.el.dom).on('click', toggle.bind(this));
},
focusenter: function (sender, event, opt) {
var _a;
if (((_a = sender.ownerCt) === null || _a === void 0 ? void 0 : _a.xtype) === 'celleditor') {
// 表格内编辑框,获取焦点后自动弹开
toggle.call(this, event);
}
},
destory: function () {
$(this.el.dom).off('click', toggle.bind(this));
},
});
initComponent.call(this);
},
focus2: function () {
this.focus();
var that = this;
_$2.defer(function () {
if (that.isExpanded) {
that.collapse();
}
else {
that.expand();
that.doQuery(that.allQuery, true);
}
});
}
});
}
function initComboGridMulti () {
Ext.define('Yvan.LocalComboGrid', {
extend: 'Ext.form.field.Picker',
// extend: 'Yvan.PickerAlignCenter',
xtype: 'combogridmulti',
triggerCls: Ext.baseCSSPrefix + 'form-arrow-trigger',
config: __assign(__assign({}, comboGridMulti), { store: null, displayField: null, columns: null, selectOnTab: true, maxPickerHeight: 300, minPickerHeight: 100, minPickerWidth: 350, rootVisible: true }),
editable: false,
initComponent: function () {
this.on({
afterrender: function () {
var config = this.config;
if (config.dataSource && config.autoLoad) {
dataSourceReload(this);
}
},
});
this.superclass.initComponent.apply(this, arguments);
},
setStore: function (store) {
this.store = store;
var me = this;
if (me.store) {
if (me.picker) {
me.picker.setStore(store);
if (me.isExpanded) {
me.collapse();
delete me.picker;
me.expand();
}
}
this.onLoad();
me.mon(me.store, {
scope: me,
load: me.onLoad,
update: me.onUpdate
});
}
},
reload: function () {
dataSourceReload(this);
},
setData: function (value) {
var me = this;
var config = me.config;
if (!value) {
return;
}
if (!this.store) {
this.store = new Ext.data.Store({
fields: [config.valueField, config.displayField],
data: value
});
}
else {
this.store.getProxy().setData(value);
this.store.load();
}
this.onLoad();
},
createPicker: function () {
var me = this;
var picker = new Ext.grid.Panel(__assign(__assign({}, comboGridMultiPicker), { border: false, baseCls: Ext.baseCSSPrefix + 'boundlist', shrinkWrapDock: 2, store: me.store, floating: true, displayField: me.displayField, columns: me.columns, minHeight: me.minPickerHeight, maxHeight: me.maxPickerHeight, minWidth: me.minPickerWidth, manageHeight: false, shadow: false, scrollable: true, listeners: {
scope: me,
selectionchange: me.onSelectionChange,
itemkeydown: me.onPickerKeyDown
} })), view = picker.getView();
if (Ext.isIE9 && Ext.isStrict) {
view.on({
scope: me,
highlightitem: me.repaintPickerView,
unhighlightitem: me.repaintPickerView,
afteritemexpand: me.repaintPickerView,
afteritemcollapse: me.repaintPickerView
});
}
return picker;
},
repaintPickerView: function () {
var style = this.picker.getView().getEl().dom.style;
style.display = style.display;
},
onSelectionChange: function (view, record, node, rowIndex, e) {
this.selectItem(view, record);
},
onPickerKeyDown: function (treeView, record, item, index, e) {
var key = e.getKey();
if (key === e.ENTER || (key === e.TAB && this.selectOnTab)) {
this.selectItem(treeView, record);
}
},
selectItem: function (sender, record) {
var me = this;
var ids = [];
_$2.forEach(me.picker.getSelection(), function (record) {
ids.push(record.get(me.valueField));
});
me.fireEvent('select', me, record);
me.setValue(ids.join(me.splitChar));
// me.collapse();
},
onExpand: function () {
var me = this;
var picker = this.picker;
var value = this.value;
if (!me.store) {
msg('正在初始化数据,请稍后');
me.collapse();
return;
}
var vs = _$2.split(value, me.splitChar);
var records = me.store.queryRecordsBy(function (r) { return _$2.findIndex(vs, function (i) { return r.get(me.valueField) === i; }) >= 0; });
picker.setSelection(records);
},
setValue: function (value) {
var me = this;
console.log('setValue', value);
me.value = value;
if (!me.store || me.store.loading) {
// Called while the Store is loading. Ensure it is processed by the onLoad method.
return me.mixins.field.setValue.call(me, value);
// return me;
}
var vs = _$2.split(value, me.splitChar);
var displayValues = [];
_$2.forEach(vs, function (v) {
var _a;
var record = me.store.queryRecordsBy(function (r) { return r.get(me.valueField) === v; });
var dv = (_a = record[0]) === null || _a === void 0 ? void 0 : _a.get(me.displayField);
if (dv) {
displayValues.push(dv);
}
else {
displayValues.push(v);
}
});
// set the raw value to the record's display field if a record was found
me.setRawValue(displayValues.join(me.splitChar));
return me.mixins.field.setValue.call(me, value);
},
getSubmitValue: function () {
return this.value;
},
getValue: function () {
return this.value;
},
onLoad: function () {
var value = this.value;
if (value) {
this.setValue(value);
}
},
onUpdate: function (store, rec, type, modifiedFieldNames) {
var display = this.displayField;
var me = this;
if (type === 'edit' && modifiedFieldNames &&
Ext.Array.contains(modifiedFieldNames, display) &&
this.value === rec.getId()) {
me.mixins.field.setValue.call(me, this.value);
this.setRawValue(rec.get(display));
}
}
});
}
function initSearch () {
Ext.define('Yvan.Search', {
extend: 'Ext.form.field.Text',
alias: 'widget.searchfield',
xtype: 'searchfield',
constructor: function (config) {
var self = this;
var newConfig = _$2.defaultsDeep({
// 强制性属性
triggers: {
clear: {
weight: 0,
cls: Ext.baseCSSPrefix + 'form-clear-trigger',
hidden: true,
handler: 'onClearClick',
},
search: {
weight: 1,
cls: Ext.baseCSSPrefix + 'form-search-trigger',
handler: 'onSearchClick'
},
},
listeners: {
blur: function (sender, e) {
this.revertOnblur();
},
specialkey: function (sender, e) {
var _a;
var me = this;
if (e.getKey() === e.ENTER) {
me.onSearchClick(sender, {}, e);
return;
}
invokeMethod((_a = config.listeners) === null || _a === void 0 ? void 0 : _a.afterrender, sender, e);
},
afterrender: function (sender, e) {
var _a;
this.replaceRawInputEvent();
invokeMethod((_a = config.listeners) === null || _a === void 0 ? void 0 : _a.afterrender, sender, e);
}
},
}, baseConfig(config, 'col-item'), config, search);
this.superclass.constructor.call(self, newConfig);
},
revertOnblur: function () {
this.setRawValue(this.lastValue);
},
onSearchClick: function (sender, vv, e) {
var me = this;
var config = me.config;
var widget = config.widget, vjson = config.vjson, lookup = config.lookup;
if (e) {
e.preventDefault();
e.stopPropagation();
}
this.fireEvent('search', sender, e);
if (!widget) {
return;
}
showWidget(widget, lookup, sender, me.getRawValue(), vjson);
},
replaceRawInputEvent: function () {
var me = this;
var $dom = $(me.inputEl.dom);
$dom.on('input', function (e) {
stopEvent(e);
// console.log('has input', e)
});
$dom.on('keyup', function (e) {
if (e.key === "Enter") {
me.onSearchClick(me, {}, e);
return;
}
stopEvent(e);
});
$dom.on('change', function (e) {
stopEvent(e);
});
},
onChange: function (newVal, oldVal) {
var me = this;
var value = newVal;
if (value) {
me.getTrigger('clear').show();
me.updateLayout();
}
else {
me.getTrigger('clear').hide();
me.updateLayout();
}
},
/**
* 清空所有值
*/
onClearClick: function (sender, e) {
var me = this;
var config = me.config;
var lookup = config.lookup;
me.setValue('');
clearViewModelByLookup(sender, lookup);
}
});
}
function initMultipleSearch () {
Ext.define('Yvan.MultipleSearch', {
extend: 'Ext.form.field.Text',
xtype: 'multiplesearch',
bindTargert: '',
constructor: function (config) {
var _a, _b, _c, _d;
var self = this;
var newConfig = _$2.defaultsDeep({
// 强制性属性
triggers: {
clear: {
weight: 0,
cls: Ext.baseCSSPrefix + 'form-clear-trigger',
hidden: true,
handler: 'onClearClick',
}
},
transformRawValue: function (o) {
return o;
},
listeners: {
specialkey: function (sender, e) {
var me = this;
if (e.getKey() === e.ENTER) {
me.fireEvent('search', me, e);
}
},
afterrender: function (sender, e) {
var _a;
this.replaceRawInputEvent();
invokeMethod((_a = config.listeners) === null || _a === void 0 ? void 0 : _a.afterrender, sender, e);
}
},
}, baseConfig(config, 'col-item'), config, search);
this.superclass.constructor.call(self, newConfig);
var vv = (_d = (((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.bind) === null || _b === void 0 ? void 0 : _b.value) || ((_c = this.config) === null || _c === void 0 ? void 0 : _c.bind))) !== null && _d !== void 0 ? _d : '';
vv = _$2.replace(vv, "{", "");
vv = _$2.replace(vv, "}", "");
this.bindTargert = vv;
this.bindTargert = _$2.trim(this.bindTargert);
},
setBindValue: function (arrValue) {
if (this.bindTargert) {
this.lookupViewModel().yvanScope.viewModel.set(this.bindTargert, arrValue);
}
},
replaceRawInputEvent: function () {
var me = this;
var $dom = $(me.inputEl.dom);
$dom.on('input', function (e) {
var _a, _b, _c, _d, _e, _f;
if ((_b = (_a = e.currentTarget) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.endsWith(" ")) {
var a = _$2.trimEnd((_c = e.currentTarget) === null || _c === void 0 ? void 0 : _c.value);
if (!a.endsWith(",") && a.length > 0) {
e.currentTarget.value = a + ",";
}
else {
e.currentTarget.value = a;
}
}
e.currentTarget.value = (_d = e.currentTarget.value) === null || _d === void 0 ? void 0 : _d.replaceAll(",,", ",");
var arr = (_f = (_e = e.currentTarget) === null || _e === void 0 ? void 0 : _e.value) === null || _f === void 0 ? void 0 : _f.split(",");
_$2.remove(arr, function (it) {
return !it;
});
me.setBindValue(arr);
stopEvent(e);
});
$dom.on('keyup', function (e) {
me.fireEvent('keyup', me, e);
// invokeMethod(me.config.listeners?.keyup, me, e)
stopEvent(e);
});
$dom.on('keydown', function (e) {
me.fireEvent('keydown', me, e);
// invokeMethod(me.config.listeners?.keydown, me, e)
//stopEvent(e)
});
$dom.on('change', function (e) {
stopEvent(e);
});
$dom.on('paste', function (e) {
var _a;
// @ts-ignore
var clipdata = e.originalEvent.clipboardData || window.clipboardData;
var text = clipdata.getData("text/plain");
var spliter = ',';
text = text.replaceAll("\r", "");
text = text.replaceAll("\n", spliter);
text = ((_a = e.currentTarget) === null || _a === void 0 ? void 0 : _a.value) + "," + text;
var arr = text.split(spliter);
if (arr && Array.isArray(arr)) {
for (var i = 0; i < arr.length; i++) {
arr[i] = _$2.trim(arr[i]);
}
}
_$2.remove(arr, function (it) {
return !it;
});
me.setBindValue(arr);
stopEvent(e);
});
},
onChange: function (newVal, oldVal) {
var me = this;
var value = newVal;
if (value) {
me.getTrigger('clear').show();
me.updateLayout();
}
else {
me.getTrigger('clear').hide();
me.updateLayout();
}
},
/**
* 清空所有值
*/
onClearClick: function (sender, e) {
var me = this;
var config = me.config;
var lookup = config.lookup;
me.setValue('');
clearViewModelByLookup(sender, lookup);
}
});
}
function initDate () {
var cc = Ext.form.field.Date.prototype.constructor;
var _a = Ext.form.field.Date.prototype, initComponent = _a.initComponent, getValue = _a.getValue, valueToRaw = _a.valueToRaw;
Ext.form.field.Date.override({
format: 'Y-m-d',
altFormats: 'Y-m-d',
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制属性
}, baseConfig(config, 'col-item'), config, date);
cc.call(this, newConfig);
},
getValue: function () {
var ov = getValue.call(this);
var nv = Ext.util.Format.date(ov, 'Y-m-d');
// console.log('cc:', nv, ov)
return nv;
},
// focus2() {
// const that = this
// if (that.isExpanded) {
// that.collapse()
//
// } else {
// that.expand();
// }
// _.defer(() => {
// that.focus()
// })
// },
initComponent: function () {
this.on({
afterrender: function () {
var config = this.config;
// 日期框,不要默认弹出
// $(this.el.dom).on('click', toggle.bind(this))
},
destory: function () {
// 日期框,不要默认弹出
// $(this.el.dom).off('click', toggle.bind(this))
},
change: {
fn: function (sender) {
if (sender.format === 'Y-m-d') {
// 年月日格式
var value = sender.getRawValue();
if (/^\d{8}$/.test(value)) {
// 8位数字,自动转换为 YYYY-MM-DD
var newValue = [
value.substr(0, 4),
value.substr(4, 2),
value.substr(6, 2)
].join('-');
sender.setValue(newValue);
}
}
},
}
// focus: {
// // 获得焦点后自动下拉
// fn(sender) {
// sender.expand();
// this.doQuery(this.allQuery, true);
// },
// },
});
initComponent.call(this);
},
createInitialDate: function (value) {
var minValue = this.minValue, maxValue = this.maxValue;
value = value || syncDate(new Date());
if (minValue && minValue > value) {
value = minValue;
}
else if (maxValue && maxValue < value) {
value = maxValue;
}
return value;
},
});
}
function initDateTimePicker () {
Ext.define('Yvan.DateTimePicker', {
extend: 'Ext.picker.Date',
alias: 'datetimepicker',
alternateClassName: 'Ext.DateTimePicker',
renderTpl: [
'
',
'
',
'',
'
{%this.renderMonthBtn(values, out)%}
',
'',
'
',
'
',
'',
'
',
'',
'
',
'
{.:this.firstInitial}
',
'
',
'',
'
',
'',
'',
'
',
'',
'{#:this.isEndOfWeek}',
'
',
'',
'
',
'',
'
',
'',
'
',
'',
'',
'',
// These elements are used with Assistive Technologies such as screen readers
'
{todayText}.
',
'
{ariaMinText}.
',
'
{ariaMaxText}.
',
'
{ariaDisabledDaysText}.
',
'
{ariaDisabledDatesText}.
',
'
',
{
firstInitial: function (value) {
return Ext.picker.Date.prototype.getDayInitial(value);
},
isEndOfWeek: function (value) {
// convert from 1 based index to 0 based
// by decrementing value once.
value--;
// eslint-disable-next-line vars-on-top
var end = value % 7 === 0 && value !== 0;
return end ? '
' : '';
},
renderTodayBtn: function (values, out) {
Ext.DomHelper.generateMarkup(values.$comp.todayBtn.getRenderTree(), out);
},
renderMonthBtn: function (values, out) {
Ext.DomHelper.generateMarkup(values.$comp.monthBtn.getRenderTree(), out);
}
}
],
beforeRender: function () {
var me = this, today = Ext.Date.format(syncDate(new Date()), me.format);
this.superclass.beforeRender.call(this);
function handleInput(extHandle, $input) {
var $dom = $(extHandle.el.dom);
// const $up = $dom.find('.x-form-spinner-up')
// const $down = $dom.find('.x-form-spinner-down')
// debugger
// $up.on('mousedown', () => {
// debugger
// });
// $up.on('click', () => {
// debugger
// });
extHandle.on('click', function (sender) {
var hideBak = me.hide;
me.hide = Ext.emptyFn;
extHandle.focus();
me.hide = hideBak;
});
var changeValue = function (delta) {
if (_$2.trim(extHandle.getValue()) === '') {
extHandle.setValue(extHandle.minValue);
}
else {
var v = parseInt('' + extHandle.getValue());
if (v + delta > extHandle.maxValue) {
extHandle.setValue(extHandle.minValue);
}
else if (v + delta < extHandle.minValue) {
extHandle.setValue(extHandle.maxValue);
}
else {
extHandle.setValue(v + delta);
}
}
};
$input.on('mousewheel', function (e) {
e.stopPropagation();
var event = e.originalEvent;
var eventDelta = event.wheelDelta || -event.deltaY + 40;
// if (event.wheelDelta) {
// delta = event.wheelDelta / 120;
// } else if (event.detail) {
// delta = -event.detail / 3;
// }
var zoomSize = Math.ceil(eventDelta / 120);
changeValue(zoomSize);
// console.log('delta', delta)
// $input.focus()
});
}
me.input1 = Ext.create('Ext.form.field.Number', {
minValue: 0,
maxValue: 23,
flex: 1,
enableKeyEvents: true,
fieldLabel: '时',
labelWidth: 20,
hideLabel: true,
spinDownEnabled: false,
spinUpEnabled: false,
style: {
marginLeft: '5px',
},
listeners: {
afterrender: function (sender) {
var $input = $(sender.inputEl.dom);
handleInput(me.input1, $input);
},
change: function (sender, e) {
if (me.getValue()) {
me.value.setHours(sender.getValue());
}
},
}
});
me.input2 = Ext.create('Ext.form.field.Number', {
minValue: 0,
maxValue: 59,
flex: 1,
enableKeyEvents: true,
fieldLabel: ' ',
hideLabel: false,
labelWidth: 8,
spinDownEnabled: false,
spinUpEnabled: false,
listeners: {
afterrender: function (sender) {
var $input = $(sender.inputEl.dom);
handleInput(me.input2, $input);
},
change: function (sender, e) {
if (me.getValue()) {
me.value.setMinutes(sender.getValue());
}
},
}
});
me.input3 = Ext.create('Ext.form.field.Number', {
minValue: 0,
maxValue: 59,
flex: 1,
enableKeyEvents: true,
fieldLabel: ' ',
hideLabel: false,
labelWidth: 8,
spinDownEnabled: false,
spinUpEnabled: false,
style: {
marginRight: '5px',
},
listeners: {
afterrender: function (sender) {
var $input = $(sender.inputEl.dom);
handleInput(me.input3, $input);
},
change: function (sender, e) {
if (me.getValue()) {
me.value.setSeconds(sender.getValue());
}
},
}
});
me.confirmBtn = new Ext.button.Button({
text: '确认',
handler: me.confirmClick,
scope: me
});
me.tdBtn = new Ext.button.Button({
text: '现在',
handler: me.selectToday,
scope: me
});
me.todayBtn = Ext.create('Ext.container.Container', {
layout: 'anchor', border: false,
defaults: {
border: false, anchor: '100%',
margin: '0 0 5 0',
},
items: [
{
layout: 'hbox',
items: [
me.input1,
me.input2,
me.input3,
]
},
{
layout: 'hbox',
items: [
me.confirmBtn,
me.tdBtn,
]
}
]
});
},
// finishRenderChildren() {
// var me = this;
//
// this.superclass.finishRenderChildren.call(this);
// //*
// me.input1.finishRender();
// me.input2.finishRender();
// me.input3.finishRender();
// //
// me.tdBtn.finishRender();
// me.confirmBtn.finishRender();
// },
setValue: function (value) {
//this.value = Ext.Date.clearTime(value, true);
this.value = value;
this.input1.setValue(this.value.getHours());
this.input2.setValue(this.value.getMinutes());
this.input3.setValue(this.value.getSeconds());
return this.update(this.value);
},
selectDate: function (value) {
if (this.showTime) {
value.setHours(this.input1.getValue());
value.setMinutes(this.input2.getValue());
value.setSeconds(this.input3.getValue());
}
this.value = value;
return this.update(this.value);
},
setDisabledStatus: function (disabled) {
var me = this;
debugger;
// me.callParent();
if (me.showTime) {
me.confirmBtn.setDisabled(disabled);
}
if (me.isShowFooter()) {
me.footerContainer.setDisabled(disabled);
}
},
handleDateClick: function (e, t) {
var me = this, handler = me.handler;
// e.stopEvent();
if (!me.disabled && t.dateValue && !Ext.fly(t.parentNode).hasCls(me.disabledCellCls)) {
me.doCancelFocus = me.focusOnSelect === false;
me.selectDate(new Date(t.dateValue));
delete me.doCancelFocus;
/* 有时间输入时单击事件不退出选择,只移动光标 */
if (me.showTime) {
return;
}
me.fireEvent('select', me, me.value);
if (handler) {
handler.call(me.scope || me, me, me.value);
}
me.onSelect();
}
},
selectToday: function () {
var me = this, btn = me.todayBtn, handler = me.handler;
if (btn && !btn.disabled) {
me.value = syncDate(new Date());
me.update(me.value);
me.fireEvent('select', me, me.value);
if (handler) {
handler.call(me.scope || me, me, me.value);
}
me.onSelect();
me.hide();
}
return me;
},
confirmClick: function () {
var me = this, btn = me.confirmBtn, handler = me.handler;
if (btn && !btn.disabled) {
me.fireEvent('select', me, me.value);
if (handler) {
handler.call(me.scope || me, me, me.value);
}
me.onSelect();
me.hide();
}
return me;
},
selectedUpdate: function (date) {
var me = this,
//t = date.getTime(),
t = Ext.Date.clearTime(date, true).getTime(), cells = me.cells, cls = me.selectedCls, cellItems = cells.elements, c, cLen = cellItems.length, cell;
cells.removeCls(cls);
for (c = 0; c < cLen; c++) {
cell = Ext.fly(cellItems[c]);
if (cell.dom.firstChild.dateValue == t) {
me.fireEvent('highlightitem', me, cell);
cell.addCls(cls);
if (me.isVisible() && !me.doCancelFocus) {
Ext.fly(cell.dom.firstChild).focus(50);
}
break;
}
}
},
// private, inherit docs
beforeDestroy: function () {
var me = this;
if (me.rendered) {
Ext.destroy(me.input1, me.input2, me.input3, me.confirmBtn, me.tdBtn, me.todayBtn);
}
me.superclass.beforeDestroy.call(this);
}
});
}
function initDateTime () {
Ext.define('Yvan.DateTimeField', {
extend: 'Ext.form.field.Date',
xtype: 'datetimefield',
alternateClassName: ['Ext.form.DateTimeField', 'Ext.form.DateTime'],
triggerCls: Ext.baseCSSPrefix + 'form-arrow-trigger',
showTime: true,
format: "Y-m-d H:i:s",
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制属性
}, baseConfig(config, 'col-item'), config, date);
this.superclass.constructor.call(this, newConfig);
},
initComponent: function () {
this.superclass.initComponent.call(this);
var setInitValue = function () {
var value = this.getRawValue();
if (!value) {
// 没填内容的时候,自动设置当前时间
this.setValue(Ext.util.Format.date(syncDate(new Date()), this.format));
}
};
this.on({
afterrender: function () {
var config = this.config;
// 日期框,不要默认弹出
$(this.el.dom).on('click', setInitValue.bind(this));
},
destory: function () {
// 日期框,不要默认弹出
$(this.el.dom).off('click', setInitValue.bind(this));
},
change: {
fn: function (sender) {
if (sender.format === "Y-m-d H:i:s") {
// 年月日格式
var value = sender.getRawValue();
if (/^\d{14}$/.test(value)) {
// 8位数字,自动转换为 YYYY-MM-DD
var newValue = [
value.substr(0, 4),
'-',
value.substr(4, 2),
'-',
value.substr(6, 2),
' ',
value.substr(8, 2),
':',
value.substr(10, 2),
':',
value.substr(12, 2)
].join('');
sender.setValue(newValue);
}
}
},
}
});
},
getValue: function () {
var ov = this.getRawValue(); //this.superclass.getValue.call(this)
var nv = Ext.util.Format.date(ov, 'Y-m-d H:i:s');
// console.log('cc:', nv, ov)
return nv;
},
onExpand: function () {
var strValue = this.getValue();
var value;
if (/^\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d$/.test(strValue)) {
value = new Date(parseInt(strValue.substr(0, 4)), parseInt(strValue.substr(5, 2)) - 1, parseInt(strValue.substr(8, 2)), parseInt(strValue.substr(11, 2)), parseInt(strValue.substr(14, 2)), parseInt(strValue.substr(17, 2)));
}
else if (/^\d\d\d\d-\d\d-\d\d$/.test(strValue)) {
value = new Date(parseInt(strValue.substr(0, 4)), parseInt(strValue.substr(5, 2)) - 1, parseInt(strValue.substr(8, 2)));
}
else {
value = syncDate(new Date());
}
this.picker.setValue(value);
},
createPicker: function () {
var me = this, format = Ext.String.format;
//@ts-ignore
return new Yvan.DateTimePicker({
pickerField: me,
ownerCt: me.ownerCt,
renderTo: document.body,
floating: true,
hidden: true,
focusOnShow: true,
minDate: me.minValue,
maxDate: me.maxValue,
disabledDatesRE: me.disabledDatesRE,
disabledDatesText: me.disabledDatesText,
disabledDays: me.disabledDays,
disabledDaysText: me.disabledDaysText,
format: me.format,
showToday: me.showToday,
showTime: me.showTime,
startDay: me.startDay,
minText: format(me.minText, me.formatDate(me.minValue)),
maxText: format(me.maxText, me.formatDate(me.maxValue)),
listeners: {
scope: me,
select: me.onSelect
},
keyNavConfig: {
esc: function () {
me.collapse();
}
}
});
},
});
}
function initNumber () {
var cc = Ext.form.field.Number.prototype.constructor;
var initComponent = Ext.form.field.Number.prototype.initComponent;
Ext.form.field.Number.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制属性
}, baseConfig(config, 'col-item'), config, numberfield);
cc.call(this, newConfig);
},
initComponent: function () {
this.on({
afterrender: function (sender) {
var _this = this;
var _a;
if ((_a = sender.inputEl) === null || _a === void 0 ? void 0 : _a.dom) {
sender.inputEl.dom.setAttribute('spellcheck', "false");
$$2(sender.inputEl.dom).on('click', function (e) {
sender.fireEvent('click', _this, e);
});
}
}
});
initComponent.call(this);
},
});
}
function initCheckbox () {
var cc = Ext.form.field.Checkbox.prototype.constructor;
var _a = Ext.form.field.Checkbox.prototype, initComponent = _a.initComponent, getValue = _a.getValue, setValue = _a.setValue;
Ext.form.field.Checkbox.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制属性
}, baseConfig(config, 'col-item'), config, checkbox);
cc.call(this, newConfig);
},
getValue: function () {
var _a = this, checkedValue = _a.checkedValue, uncheckedValue = _a.uncheckedValue;
var ov = getValue.call(this);
// const ov = this.getRawValue()
return (ov ? checkedValue : uncheckedValue);
},
setValue: function (nv) {
var _a = this, checkedValue = _a.checkedValue, uncheckedValue = _a.uncheckedValue;
var value;
if (nv === checkedValue) {
value = true;
}
else if (nv === uncheckedValue) {
value = false;
}
else {
value = !!nv;
}
// me.setRawValue(value)
// me.checked = value
// return me.mixins.field.setValue.call(me, value);
setValue.call(this, value);
},
updateCheckedCls: function (checked) {
var me = this;
var _a = this, uncheckedValue = _a.uncheckedValue, checkedValue = _a.checkedValue;
checked = checked != null ? checked : me.getValue();
if (checked === uncheckedValue) {
checked = false;
}
else if (checked === checkedValue) {
checked = true;
}
me[checked ? 'addCls' : 'removeCls'](me.checkedCls);
},
initComponent: function () {
initComponent.call(this);
},
});
}
function initCheckboxGroup () {
var cc = Ext.form.CheckboxGroup.prototype.constructor;
var initComponent = Ext.form.CheckboxGroup.prototype.initComponent;
Ext.form.CheckboxGroup.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制属性
}, baseConfig(config, 'col-item'), config, checkboxgroup);
cc.call(this, newConfig);
},
initComponent: function () {
initComponent.call(this);
},
});
}
function initRadio () {
var cc = Ext.form.field.Radio.prototype.constructor;
var initComponent = Ext.form.field.Radio.prototype.initComponent;
Ext.form.field.Radio.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制属性
}, baseConfig(config, 'col-item'), config, radio);
cc.call(this, newConfig);
},
initComponent: function () {
initComponent.call(this);
},
});
}
function initRadioGroup () {
var cc = Ext.form.RadioGroup.prototype.constructor;
var initComponent = Ext.form.RadioGroup.prototype.initComponent;
Ext.form.RadioGroup.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({
// 强制属性
}, baseConfig(config, 'col-item'), config, radiogroup);
cc.call(this, newConfig);
},
initComponent: function () {
initComponent.call(this);
},
});
}
function initFieldset () {
/**
*
*/
var ct = Ext.form.FieldSet.prototype.constructor;
Ext.form.FieldSet.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({}, config, baseConfig(config, "rows-container"), fieldSet);
ct.call(this, newConfig);
}
});
}
function initCombotree () {
Ext.define('Yvan.ComboTree', {
extend: 'Ext.form.field.Picker',
xtype: 'combotree',
triggerCls: Ext.baseCSSPrefix + 'form-arrow-trigger',
config: {
store: null,
displayField: null,
columns: null,
selectOnTab: true,
maxPickerHeight: 300,
minPickerHeight: 100,
minPickerWidth: 350,
rootVisible: true,
},
editable: false,
setStore: function (store) {
this.store = store;
var me = this;
if (me.store) {
if (me.picker) {
me.picker.setStore(store);
if (me.isExpanded) {
me.collapse();
delete me.picker;
me.expand();
}
}
this.onLoad();
me.mon(me.store, {
scope: me,
load: me.onLoad,
update: me.onUpdate
});
}
},
createPicker: function () {
var me = this;
var picker = new Ext.tree.Panel({
border: false,
baseCls: Ext.baseCSSPrefix + 'boundlist',
shrinkWrapDock: 2,
store: me.store,
floating: true,
rootVisible: me.rootVisible,
displayField: me.displayField,
columns: me.columns,
minHeight: me.minPickerHeight,
maxHeight: me.maxPickerHeight,
minWidth: me.minPickerWidth,
manageHeight: false,
shadow: false,
scrollable: true,
// modal: true,
// constrain: true,
// constrainTo: topScope._handle.el.dom,
// renderTo: topScope._handle.el.dom,
// alignTarget: topScope._handle,
listeners: {
scope: me,
itemclick: me.onItemClick,
itemkeydown: me.onPickerKeyDown
}
}), view = picker.getView();
if (Ext.isIE9 && Ext.isStrict) {
view.on({
scope: me,
highlightitem: me.repaintPickerView,
unhighlightitem: me.repaintPickerView,
afteritemexpand: me.repaintPickerView,
afteritemcollapse: me.repaintPickerView
});
}
return picker;
},
repaintPickerView: function () {
var style = this.picker.getView().getEl().dom.style;
style.display = style.display;
},
onItemClick: function (view, record, node, rowIndex, e) {
this.selectItem(view, record);
},
onPickerKeyDown: function (treeView, record, item, index, e) {
var key = e.getKey();
if (key === e.ENTER || (key === e.TAB && this.selectOnTab)) {
this.selectItem(treeView, record);
}
},
selectItem: function (sender, record) {
var me = this;
me.setValue(record.getId());
me.fireEvent('select', me, record);
me.collapse();
},
onExpand: function () {
var picker = this.picker;
var store = picker.store;
var value = this.value;
var node;
if (value) {
node = store.getNodeById(value);
}
if (!node) {
node = store.getRoot();
}
picker.ensureVisible(node, {
select: true,
focus: true
});
},
setValue: function (value) {
var me = this;
console.log('setValue', value);
me.value = value;
if (!me.store || me.store.loading) {
// Called while the Store is loading. Ensure it is processed by the onLoad method.
return me.mixins.field.setValue.call(me, value);
// return me;
}
var record = value ? me.store.getNodeById(value) : me.store.getRoot();
if (value === undefined) {
record = me.store.getRoot();
console.log('setValue', record.getId());
me.value = record.getId();
return me.mixins.field.setValue.call(me, value);
}
else {
record = me.store.getNodeById(value);
}
// set the raw value to the record's display field if a record was found
me.setRawValue(record ? record.get(me.displayField) : '');
return me.mixins.field.setValue.call(me, value);
},
getSubmitValue: function () {
return this.value;
},
getValue: function () {
return this.value;
},
onLoad: function () {
var value = this.value;
if (value) {
this.setValue(value);
}
},
onUpdate: function (store, rec, type, modifiedFieldNames) {
var display = this.displayField;
var me = this;
if (type === 'edit' && modifiedFieldNames &&
Ext.Array.contains(modifiedFieldNames, display) &&
this.value === rec.getId()) {
me.mixins.field.setValue.call(me, this.value);
this.setRawValue(rec.get(display));
}
}
});
}
function initPickerPlus () {
Ext.define('Yvan.PickerAlignCenter', {
extend: 'Ext.form.field.Picker',
/**
* Performs the alignment on the picker using the class defaults
* @private
*/
doAlign: function () {
// 不要挪动就好
},
});
}
function initCombogrid () {
Ext.define('Yvan.ComboGrid', {
extend: 'Ext.form.field.Picker',
// extend: 'Yvan.PickerAlignCenter',
xtype: 'combogrid',
triggerCls: Ext.baseCSSPrefix + 'form-search-trigger',
triggers: {
clear: {
weight: 0,
cls: Ext.baseCSSPrefix + 'form-clear-trigger',
hidden: true,
handler: 'onClearClick',
},
},
config: __assign({}, comboGrid),
editable: true,
_superBlur: false,
allowCustomInput: false,
pressEnterPopup: true,
initComponent: function () {
var that = this;
var scope = lookupScope(that);
var config = that.config;
if (isDesignMode(scope, config)) {
this.superclass.initComponent.call(this, arguments);
return;
}
this.on({
blur: function (sender, e) {
if (this._superBlur) {
// 挂起时不恢复内容
return;
}
// 离开焦点时,恢复原来的值
sender.setRawValue(sender.value);
},
afterrender: function (sender) {
var $dom = $(sender.inputEl.dom);
that.scope = lookupScope(sender);
if (sender.column) {
// 列模式,拦截 keydown
$dom.on('keydown', function (e) {
if (isChartEvent(e) && !that.tryEnable()) {
// 没有达成 editEnable 条件,不用响应
stopEvent(e);
return;
}
if (that.pressEnterPopup !== false && e.key === 'Enter') {
stopEvent(e);
that.onTriggerClick(that, that.getPickerTrigger(), e);
return;
}
});
}
else {
// 常规模式,拦截 keyup
$dom.on('keyup', function (e) {
if (e.key === 'Escape' || e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
return;
}
if (isChartEvent(e) && !that.tryEnable()) {
// 没有达成 editEnable 条件,不用响应
stopEvent(e);
return;
}
if (that.pressEnterPopup !== false && e.key === 'Enter') {
stopEvent(e);
that.onTriggerClick(that, that.getPickerTrigger(), e);
return;
}
if (!that.allowCustomInput) {
// 取消 keyup 事件,让 ext 不要吧当前输入的值记录到 value 中
stopEvent(e);
}
});
$dom.on('change', function (e) {
// 这里注释掉,是因为 当鼠标点击触发弹出后,会导致取"e.target.value"值无效
// if (that.isExpanded) {
// that.filterChange(that, e.target.value)
// }
stopEvent(e);
});
}
$dom.on('input', function (e) {
stopEvent(e);
});
},
});
this.superclass.initComponent.apply(this, arguments);
},
createPicker: function () {
var me = this;
var cfg = {
layout: 'fit',
border: 0,
// border: 5,
style: {
// borderColor: 'black',
// borderWidth: '5px',
// borderStyle: 'solid',
boxShadow: '0px 2px 5px rgba(0,0,0,.5)'
},
shadow: 'side',
shadowOffset: 100,
baseCls: Ext.baseCSSPrefix + 'boundlist',
shrinkWrapDock: 2,
floating: true,
width: me.pickerWidth,
height: me.pickerHeight,
minWidth: me.pickerWidth,
minHeight: me.pickerHeight,
maxWidth: me.pickerWidth,
maxHeight: me.pickerHeight,
items: [
__assign(__assign(__assign({}, comboGridPicker), me.grid), { tbar: {
xtype: 'toolbar',
items: [
{ xtype: 'textfield', fieldLabel: '筛选' },
{
xtype: 'button',
text: '查询',
iconCls: 'x-fa fa-search',
cssType: 'primary',
listeners: {
click: function () {
me.reloadGrid();
}
}
},
]
}, autoLoad: false, listeners: {
afterrender: function (grid) {
me.grid = grid;
grid.focus();
grid.on({
rowdblclick: function (sender, row) {
me.selectItem(row);
},
dataLoadComplete: function (sender) {
_$2.defer(function () {
me.setFocus();
});
},
keydown: function (sender, e) {
if (me.column) {
// 列模式,拦截 keydown
me.processKey(e);
}
},
keyup: function (sender, e) {
if (!me.column) {
// 常规模式,拦截 keyup
me.processKey(e);
}
}
});
},
} })
]
};
// @ts-ignore
var picker = new Ext.container.Container(cfg);
return picker;
},
setFocus: function () {
if (this.grid.store.getCount() > 0) {
this.grid.focusRow(0);
}
},
processKey: function (e) {
if (this.pressEnterPopup !== false && e.key === 'Enter') {
this.selectItem(this.grid.selection);
stopEvent(e);
}
else if (e.key === 'Escape') {
this.collapse();
}
},
repaintPickerView: function () {
var style = this.picker.getView().getEl().dom.style;
style.display = style.display;
},
onItemClick: function (view, record, node, rowIndex, e) {
this.selectItem(record);
},
onPickerKeyDown: function (treeView, record, item, index, e) {
var key = e.getKey();
if ((this.pressEnterPopup !== false && key === e.ENTER) || (key === e.TAB && this.selectOnTab)) {
this.selectItem(record);
}
},
filterChange: _$2.debounce(function (sender, value) {
sender.onExpand();
}, 1000),
selectItem: function (record) {
var me = this;
var lookup = this.lookup;
var scope = lookupScope(this);
me.fireEvent('select', me, record);
if (record.isModel) {
record = record.data;
}
tryWriteObject(lookup, record, function (path, value) {
me._lookupSet(path, value);
});
// lookup
// fromColumn: 'toTarget'
// fromColumn: 'toTarget'
// fromColumn: 'toTarget'
_$2.forOwn(lookup, function (toTarget, fromColumn) {
var value = _$2.get(record, fromColumn);
me._lookupSet(toTarget, value);
});
// 选定之后不能做清空
// const {lookupClearOnChange} = me
// if (_.isArray(lookupClearOnChange)) {
// _.each(lookupClearOnChange, item => {
// me._lookupSet(item, '')
// })
// }
me.collapse();
// 触发 _raiseNextFocus
me._raiseNextFocus(me);
},
onExpand: function () {
// 展开时,根据 lookup 带入查询参数
var expressData = this.getExpressData();
var txtField = this.grid.down('toolbar').down('textfield');
txtField.setValue(expressData.queryValue);
this.reloadGrid();
},
reloadGrid: function () {
// 展开时,根据 lookup 带入查询参数
var expressData = this.getExpressData();
var reloadParam = calcObjectFlat(expressData, this.param) || {};
var txtField = this.grid.down('toolbar').down('textfield');
// 每个 combogrid 默认带上 __queryValue 属性
reloadParam["__queryValue"] = txtField.getValue();
this.grid.reload(reloadParam);
},
onTriggerClick: function (sender) {
var _a = this, isExpanded = _a.isExpanded, readOnly = _a.readOnly, disabled = _a.disabled, grid = _a.grid;
if (!grid) {
msg('正在初始化,请稍后');
return;
}
if (!this.tryEnable()) {
// 没有达成 editEnable 条件,不用弹出
return;
}
if (isExpanded || readOnly || disabled) {
// 已弹出、只读、禁用状态下,不允许弹出
return;
}
this._superBlur = true;
this.superclass.onTriggerClick.apply(this, arguments);
this._superBlur = false;
},
onCollapse: function () {
// 每次收回时,删除下拉组件
// delete this.picker
},
/**
* 本方法只会从 API 或外部调用,键盘输入的内容不会记录在内
*/
setValue: function (value) {
var me = this;
// 设值用户看到的表面内容
this.setRawValue(value);
// 设值 setValue 调用链,正常触发 change 事件等
return me.mixins.field.setValue.call(me, value);
},
_lookupSet: function (path, value) {
var me = this;
path = tryVarSimple(path);
if (me.column) {
// 判断写入目标,是否与自己绑定的属性相等
if (path === 'queryValue' || me.column.dataIndex === path) {
me.setValue(value);
}
// 列模式下,写当前编辑行
var parentRecord = me._lookupEditorRecord();
if (parentRecord) {
// Ext.data.Record / Ext.data.Model
parentRecord.set(path, value);
}
else {
debugger;
}
}
else {
// 常规模式下,写 viewModel
me.scope.viewModel.set(path, value);
}
},
_lookupGrid: function () {
return this.column.up('grid');
},
_lookupEditorRecord: function () {
var _a, _b, _c, _d;
// parentGrid.getSelectionModel().getLastSelected()
var grid = this._lookupGrid();
var editingPlugin = (_a = grid.editingPlugin) !== null && _a !== void 0 ? _a : (_b = grid.ownerGrid) === null || _b === void 0 ? void 0 : _b.editingPlugin;
if (!editingPlugin) {
return grid.getSelectionModel().getLastSelected();
}
var rowIdx = (_d = (_c = editingPlugin.activeEditor) === null || _c === void 0 ? void 0 : _c.context) === null || _d === void 0 ? void 0 : _d.rowIdx;
if (_$2.isNumber(rowIdx)) {
return grid.store.getAt(rowIdx);
}
else {
return grid.getSelectionModel().getLastSelected();
}
},
onChange: function (newVal, oldVal) {
var me = this;
var value = newVal;
var hideTrigger = me.hideTrigger, disabled = me.disabled, readOnly = me.readOnly, hideClear = me.hideClear;
if (hideTrigger || disabled || readOnly || hideClear) {
// 禁用、隐藏、只读、隐藏清空状态下,不需要显示清空按钮
return;
}
if (value) {
me.getTrigger('clear').show();
me.updateLayout();
}
else {
me.getTrigger('clear').hide();
me.updateLayout();
}
},
/**
* 得到能用于 express 表达式计算的上下文数据
*/
getExpressData: function () {
var queryValue = this.getRawValue();
if (!queryValue) {
// 父 combogrid 输入的内容为空的情况下,看看弹出框内部的输入框
queryValue = this.getPicker().down('textfield').getRawValue();
}
if (this.column) {
// 列模式, 准备好判断 editEnable 表达式用的数据
var parentRecord = this._lookupEditorRecord();
if (!parentRecord) {
debugger;
}
return __assign(__assign(__assign({}, this.scope.viewModel.data), parentRecord.data), { queryValue: queryValue });
}
else {
// 编辑模式,准备好判断用的数据
return __assign(__assign({}, this.scope.viewModel.data), { queryValue: queryValue });
}
},
tryEnable: function () {
return tryEnable(this.getExpressData(), this.editEnable);
},
/**
* 清空所有值
*/
onClearClick: function (sender, e) {
var me = this;
var lookup = me.lookup, lookupClearOnChange = me.lookupClearOnChange;
me.fireEvent('clear', sender, e);
me.setValue('');
_$2.forOwn(lookup, function (toTarget, fromColumn) {
me._lookupSet(toTarget, '');
});
_$2.each(lookupClearOnChange, function (item) {
me._lookupSet(item, '');
});
}
});
}
function initContainer () {
var cc = Ext.container.Container.prototype.constructor;
//const {initComponent} = Ext.container.Container.prototype
Ext.container.Container.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({}, baseConfig(config, 'col-item'), config);
cc.call(this, newConfig);
},
});
}
function initRows () {
Ext.define('Yvan.Rows', {
extend: 'Ext.container.Container',
xtype: 'rows',
constructor: function (config) {
var self = this;
var newConfig = _$2.defaultsDeep({
// 强制性属性
layout: 'anchor', border: false,
defaults: {
border: false, anchor: '100%',
margin: '0 0 5 0',
},
}, baseConfig(config, 'rows-container'), config, rows);
this.superclass.constructor.call(self, newConfig);
},
});
}
function initForm () {
var ct = Ext.form.Panel.prototype.constructor;
Ext.form.Panel.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({}, config, baseConfig(config, "cols-container"), form);
ct.call(this, newConfig);
}
});
}
function initCols () {
Ext.define('Yvan.Cols', {
extend: 'Ext.container.Container',
xtype: 'cols',
constructor: function (config) {
var self = this;
var newConfig = _$2.defaultsDeep({
// 强制性属性
layout: 'hbox',
minHeight: config.designMode ? 32 : 0
}, baseConfig(config, 'cols-container'), config, cols);
this.superclass.constructor.call(self, newConfig);
},
});
}
function initButton () {
/**
*
*/
var ct = Ext.button.Button.prototype.constructor;
Ext.button.Button.override({
constructor: function (config) {
var newConfig = _$2.defaultsDeep({}, config, baseConfig(config, "col-item"), button);
ct.call(this, newConfig);
},
setLoading: function (value) {
if (value) {
if (this.iconCls !== 'x-fa fa-spinner fa-spin fa-fw') {
this._originIconCls = this.iconCls;
}
this.setIconCls('x-fa fa-spinner fa-spin fa-fw');
this.setDisabled(true);
}
else {
this.setIconCls(this._originIconCls);
this.setDisabled(false);
}
}
});
}
function initIframe () {
Ext.define('Ext.ux.IFrame', {
extend: 'Ext.Component',
alias: 'widget.uxiframe',
loadMask: 'Loading...',
src: 'about:blank',
renderTpl: [
''
],
childEls: ['iframeEl'],
initComponent: function () {
this.superclass.initComponent.call(this);
this.superclass.initEvents.call(this);
this.frameName = this.frameName || this.id + '-frame';
},
initEvents: function () {
var me = this;
this.superclass.initEvents.call(this);
me.iframeEl.on('load', me.onLoad, me);
},
initRenderData: function () {
return Ext.apply(this.superclass.initRenderData.call(this), {
src: this.src,
frameName: this.frameName
});
},
getBody: function () {
var doc = this.getDoc();
return doc.body || doc.documentElement;
},
getDoc: function () {
try {
return this.getWin().document;
}
catch (ex) {
return null;
}
},
getWin: function () {
var me = this, name = me.frameName, win = Ext.isIE ? me.iframeEl.dom.contentWindow : window.frames[name];
return win;
},
getFrame: function () {
var me = this;
return me.iframeEl.dom;
},
onLoad: function () {
var me = this, doc = me.getDoc();
if (doc) {
this.el.unmask();
this.fireEvent('load', this);
}
else if (me.src) {
this.el.unmask();
this.fireEvent('error', this);
}
},
load: function (src) {
var me = this, text = me.loadMask, frame = me.getFrame();
if (me.fireEvent('beforeload', me, src) !== false) {
if (text && me.el) {
me.el.mask(text);
}
frame.src = me.src = (src || me.src);
}
}
});
}
/**
* 属性:
* - autoLoad: true
* - dataSource: ''
* 方法:
* - handleZoomBig
* - handleZoomSmall
* - handleZoomReset
* - openDiagram
* - getBpmn
* - getBpmnCanvas
* - getBpmnOverlays
* - getBpmnZoomScroll
* 事件:
* - initFinish
* - failed
* - success
* - itemHover
* - itemOut
* - itemClick
* - itemDblclick
* - itemMousedown
* - itemMouseup
*/
function initBpmn () {
Ext.define('Yvan.Bpmn', {
// extend: 'Ext.container.Container',
extend: 'Ext.panel.Panel',
alias: 'widget.bpmn',
xtype: 'bpmn',
constructor: function (config) {
var self = this;
var newConfig = _$2.defaultsDeep({
// 强制性属性
}, baseConfig(config, 'row-item'), config, bpmn);
if (!newConfig.hideToolbar) {
newConfig.tbar = [];
newConfig.tbar.push({
xtype: 'button', iconCls: 'x-fa fa-refresh', tooltip: '刷新',
listeners: {
click: function (sender) {
self.reload();
}
}
});
newConfig.tbar.push({
xtype: 'button', tooltip: "放大", iconCls: "x-fa fa-search-plus",
listeners: {
click: function (sender) {
self.handleZoomBig();
}
},
});
newConfig.tbar.push({
xtype: 'button', tooltip: "缩小", iconCls: "x-fa fa-search-minus",
listeners: {
click: function (sender) {
self.handleZoomSmall();
}
},
});
newConfig.tbar.push({
xtype: 'button', tooltip: "还原", iconCls: "x-fa fa-reply",
listeners: {
click: function (sender) {
self.handleZoomReset();
}
},
});
}
this.superclass.constructor.call(self, newConfig);
},
initComponent: function () {
var _this = this;
var me = this;
var config = me.config;
var scope = lookupScope(this);
if (!isDesignMode(scope, config)) {
//@ts-ignore
require(['bpmn-modeler', 'bpmn-navigated', 'bpmn-viewer'], function (BpModeler, BpNavigated, BpmnViewer) {
console.log('BpNavigated', me, BpNavigated);
var dom = me.el.dom;
var $dom = $(dom);
var $container = $dom.find('.x-autocontainer-innerCt');
var bpmn = new BpNavigated(__assign({ container: $container[0] }, config.bpmnConfig));
_this._bpmn = bpmn;
if (_this.autoLoad) {
_this.reload();
}
_this.fireEvent('initFinish', _this);
var eventBus = bpmn.get('eventBus');
eventBus.on('element.hover', function (e) {
// this.fireEvent('itemHover', this, e);
});
eventBus.on('element.out', function (e) {
_this.fireEvent('itemOut', _this, e);
});
eventBus.on('element.click', function (e) {
_this.fireEvent('itemClick', _this, e);
});
eventBus.on('element.dblclick', function (e) {
_this.fireEvent('itemDblclick', _this, e);
});
eventBus.on('element.mousedown', function (e) {
_this.fireEvent('itemMousedown', _this, e);
});
eventBus.on('element.mouseup', function (e) {
_this.fireEvent('itemMouseup', _this, e);
});
});
}
this.superclass.initComponent.call(this);
this.on({
afterrender: function (sender) {
}
});
},
/**
* 重新载入
*/
reload: function () {
var _this = this;
var _a;
if (typeof this.dataSource === 'string' && this.dataSource) {
var scope = lookupScope(this);
var fn = lookupFn(scope, this.dataSource);
(_a = fn.call(scope, this)) === null || _a === void 0 ? void 0 : _a.then(function (res) {
_this.openDiagram(res.data);
});
}
},
/**
* 获取bpmn
*/
getBpmn: function () {
return this._bpmn;
},
getBpmnCanvas: function () {
var _a;
return (_a = this.getBpmn()) === null || _a === void 0 ? void 0 : _a.get('canvas');
},
getBpmnOverlays: function () {
var _a;
return (_a = this.getBpmn()) === null || _a === void 0 ? void 0 : _a.get('overlays');
},
getBpmnZoomScroll: function () {
var _a;
return (_a = this.getBpmn()) === null || _a === void 0 ? void 0 : _a.get('zoomScroll');
},
handleZoomBig: function () {
var _a;
(_a = this.getBpmnZoomScroll()) === null || _a === void 0 ? void 0 : _a.stepZoom(1);
},
handleZoomSmall: function () {
var _a;
(_a = this.getBpmnZoomScroll()) === null || _a === void 0 ? void 0 : _a.stepZoom(-1);
},
handleZoomReset: function () {
var _a;
(_a = this.getBpmnZoomScroll()) === null || _a === void 0 ? void 0 : _a.reset();
},
openDiagram: function (diagram) {
var _this = this;
if (!this.getBpmn()) {
return;
}
this.getBpmn().importXML(diagram, function (err) {
if (err) {
// YvEventDispatch(this.onFailed, this, undefined);
_this.fireEvent('failed', _this, err);
return console.error('could not import BPMN 2.0 diagram', err);
}
// zoom to fit full viewport
_this.getBpmnCanvas().zoom('fit-viewport');
_this.fireEvent('success', _this);
});
},
});
}
function initSqlComplex () {
Ext.define('Yvan.SqlComplex', {
extend: 'Ext.panel.Panel',
xtype: 'sqlcomplex',
alias: 'widget.sqlcomplex',
getSqlExpress: function () {
},
constructor: function (config) {
var reference = config.reference;
var me = this;
var newConfig = __assign(__assign({}, config), { layout: 'border', items: [
{
region: 'west',
width: 280,
border: false,
split: true,
reference: reference + '_tree',
xtype: 'yvtree',
hideRefresh: true,
hideExpand: true,
hideCollapse: true,
listeners: {
itemdblclick: function (sender, record, item, index, e) {
var field = record.get('field');
var defaultValue = record.get('defaultValue');
if (!field) {
return;
}
var tabExpress = me.down('tabpanel');
var sqleditor = me.down('sqleditor');
var expressGrid = me.down('yvgrid');
if (tabExpress.getActiveTab().key !== 'grid') {
// SQL 模式
sqleditor.insertText(field + '=');
}
else {
// 表格模式
expressGrid.appendEditRow({
field: field,
operator: '=',
value: defaultValue,
remark: '',
});
_$2.defer(function () {
gridChanged(me, expressGrid);
});
}
}
},
},
{
region: 'center',
xtype: 'tabpanel',
reference: reference + '_tab',
tabPosition: 'bottom',
listeners: {
afterrender: function (sender) {
var scope = lookupScope(me);
var value = scope.viewModel.get(me.config.bindValue);
// sql 转换为 grid
try {
var list_1 = parseSqlToGrid(value);
_$2.defer(function () {
var grid = me.down('yvgrid');
grid.setData(list_1);
});
}
catch (e) {
console.error(e);
msg$1('无法解析SQL语法! 目前只能以 SQL 模式打开,如果在表格中做修改,将会覆盖原语句!');
var tabSql = sender.down('sqleditor');
sender.setActiveTab(tabSql);
}
},
beforetabchange: function (sender, newCard, oldCard, eOpts) {
var scope = lookupScope(me);
var value = scope.viewModel.get(me.config.bindValue);
if (newCard.key === 'grid') {
// sql 转换为 grid
try {
var list_2 = parseSqlToGrid(value);
_$2.defer(function () {
var grid = me.down('yvgrid');
grid.setData(list_2);
});
return true;
}
catch (e) {
msg$1('无法解析 SQL 语法! 表格模式只适用于简单语法');
console.error(e);
return false;
}
}
else if (newCard.key === 'sql') {
// grid 转换为 sql
_$2.defer(function () {
var editor = me.down('sqleditor');
editor.setValue(value);
});
return true;
}
}
},
items: [
{
title: '表格模式',
key: 'grid',
xtype: 'yvgrid',
_mode: 'select',
reference: reference + '_grid',
hideFootbar: true,
pagination: false,
tbar: [
{
xtype: 'button',
text: '删除',
iconCls: 'x-fa fa-minus-circle',
cls: 'ext-btn-danger',
bind: {
disabled: '{!' + reference + '_grid.selection}',
},
listeners: {
click: function (sender) {
var grid = sender.up('yvgrid');
removeGridRow(grid);
gridChanged(me, grid);
}
},
},
],
store: {},
listeners: {
editfinish: function (sender) {
gridChanged(me, sender);
},
},
columns: [
{
dataIndex: 'field',
header: '字段', sortable: false, menuDisabled: true,
width: 190,
renderer: function (value, context, record, rowIdx, colIdx, store, view) {
var column = context.column;
var propertyConfig = me.config.propertyConfig;
// 找到 propertyConfig 对应 propertyName 名称的 dict 字典的 dict.text 值
var field = record.get('field');
if (field) {
var idx = _$2.findIndex(propertyConfig, function (p) { return p.field === field; });
if (idx >= 0) {
var meta = propertyConfig[idx];
return meta.text;
}
}
return value;
}
},
{
dataIndex: 'operator',
header: '运算符', sortable: false, menuDisabled: true,
dict: 'operator',
width: 65,
editor: { xtype: 'combo' },
},
{
dataIndex: 'value',
header: '值', sortable: false, menuDisabled: true,
flex: 1,
getEditor: function (record) {
var column = this;
var grid = _$2.get(column, 'ownerCt.grid.ownerGrid');
var propertyConfig = me.config.propertyConfig;
var field = record.get('field');
if (!field) {
// 没有填 propertyName
return;
}
var idx = _$2.findIndex(propertyConfig, function (p) { return p.field === field; });
if (idx < 0) {
console.error('没有找到 field=' + field + ". propertyConfig");
return;
}
var meta = propertyConfig[idx];
if ((record.get('operator') === 'in' || record.get('operator') === 'notIn') && meta.editor.xtype === 'combo') {
return new Ext.grid.CellEditor({
field: __assign(__assign({ dict: meta.dict }, meta.editor), { xtype: 'tagfield' })
});
}
return new Ext.grid.CellEditor({
field: __assign({ dict: meta.dict }, meta.editor)
});
},
renderer: function (valueList, context, record, rowIdx, colIdx, store, view) {
var column = context.column;
var grid = _$2.get(view, 'ownerGrid');
var propertyConfig = me.config.propertyConfig;
// 找到 propertyConfig 对应 propertyName 名称的 dict 字典的 dict.text 值
var field = record.get('field');
if (field) {
var idx = _$2.findIndex(propertyConfig, function (p) { return (p.field) === field; });
if (idx >= 0) {
var meta = propertyConfig[idx];
var dictName = _$2.get(meta, 'dict');
if (dictName && window['DICT_CACHE'][dictName]) {
var dict_1 = window['DICT_CACHE'][dictName];
var valueText_1 = [];
_$2.forEach(_$2.split(valueList, ','), function (value) {
var idxKv = _$2.findIndex(dict_1, function (kv) { return _$2.toString(kv.id) === _$2.toString(value); });
if (idxKv >= 0) {
valueText_1.push(dict_1[idxKv].text);
}
else {
valueText_1.push(value);
}
});
return valueText_1.join(',');
}
}
}
return valueList;
},
},
]
},
{
title: 'SQL模式',
key: 'sql',
xtype: 'sqleditor',
reference: reference + '_sql',
listeners: {
change: function (sender) {
var scope = lookupScope(me);
// 保存 editor 写入的值
scope.viewModel.set(me.config.bindValue, sender.getValue());
}
}
},
]
}
] });
this.superclass.constructor.call(this, newConfig);
},
initComponent: function () {
// 货位条件树
var me = this;
me.superclass.initComponent.apply(this, arguments);
var tree = this.down('yvtree');
var config = me.config;
tree.setRootNode(buildConfigTree(config.propertyConfig));
},
});
function gridChanged(me, grid) {
var data = grid.getDataRows();
var propertyConfig = me.config.propertyConfig;
var bindValue = me.config.bindValue;
var scope = lookupScope(me);
var sql = parseGridToSql(data);
scope.viewModel.set(bindValue, sql);
}
/**
* 用于从 propertyConfig 解析出树形结构
* { text: '库别分类', field: 'loc_classify', operator: '=', category: '库位属性', editor: {xtype: 'combo'}, dict: 'AREA_CLASSIFY', },
* ->
* {text: '库别分类', field: 'loc_classify', operator: '=', leaf: true},
*/
function buildConfigTree(propertyConfig) {
var root = {
expanded: true,
leaf: false,
children: []
};
var categoryObj = {};
var cfgList = propertyConfig;
_$2.forEach(cfgList, function (cfg) {
var cateNode = categoryObj[cfg.category];
if (!cateNode) {
cateNode = {
text: cfg.category, expanded: true, leaf: false,
children: []
};
categoryObj[cfg.category] = cateNode;
root.children.push(cateNode);
}
cateNode.children.push({
text: cfg.text,
field: cfg.field,
operator: cfg.operator,
defaultValue: cfg.defaultValue,
leaf: true,
});
});
return root;
}
/**
* 将表格变成 SQL where语句 [
* {field: 'f1', value: 1, operator: '='}
* {field: 'f2', value: 2, operator: '='}
* {field: 'f3', value: '3', operator: '>='}
* {field: 'f4', value: 4, operator: '='}
* ]
* ->
* f1=v1 and f2=v2
*/
function parseGridToSql(list) {
var sqls = [];
_$2.forEach(list, function (i) {
var _a;
if (i.operator === 'in') {
sqls.push(i.field + ' in (' + (i.value) + ')');
}
else if (i.operator === 'notIn') {
sqls.push(i.field + ' not in (' + (i.value) + ')');
}
else {
sqls.push(i.field + ' ' + i.operator + ' ' + ((_a = i.value) !== null && _a !== void 0 ? _a : 0));
}
});
return sqls.join(' AND ');
}
/**
* 将 SQL 语句的 where 片段变成表格
* @param sql f1=1 and f2=2 and f3>="3" and f4=4
* @return [
{field: 'f1', value: 1, operator: '='}
{field: 'f2', value: 2, operator: '='}
{field: 'f3', value: '3', operator: '>='}
{field: 'f4', value: 4, operator: '='}
]
*/
function parseSqlToGrid(sql) {
if (!sql || !_$2.trim(sql)) {
return [];
}
var parser = new window['NodeSQLParser'].Parser();
var ast = parser.astify('select * from dual where ' + sql);
var ret = [];
exp(ast.where, ret);
return ret;
}
function exp(ast, ret) {
if (ast.type === 'binary_expr') {
if (_$2.toUpper(ast.operator) === 'AND') {
if (ast.left.type === 'binary_expr') {
exp(ast.left, ret);
}
if (ast.right.type === 'binary_expr') {
exp(ast.right, ret);
}
}
else if (['=', '>=', '>', '<=', '<', 'IN', 'NOT IN'].includes(_$2.toUpper(ast.operator))) {
if (ast.left.type === 'column_ref') {
if (ast.right.type === 'number' ||
ast.right.type === 'single_quote_string' ||
ast.right.type === 'double_quote_string') {
// 具体值相等
ret.push({ field: ast.left.column, value: ast.right.value, operator: ast.operator });
}
else if ((_$2.toUpper(ast.operator) === 'IN' || _$2.toUpper(ast.operator) === 'NOT IN')
&& ast.right.type === 'expr_list') {
// in / not in
var valueList_1 = [];
_$2.forEach(ast.right.value, function (item) {
valueList_1.push(item.value);
});
var operator = void 0;
if (_$2.toUpper(ast.operator) === 'IN') {
operator = 'in';
}
else if (_$2.toUpper(ast.operator) === 'NOT IN') {
operator = 'notIn';
}
ret.push({
field: ast.left.column, value: valueList_1.join(','),
operator: operator
});
}
else {
throw new Error('ast.right must is value.');
}
}
else {
throw new Error('ast.left must is column_ref.');
}
}
else {
// 必须用 AND 条件符匹配
throw new Error('ast.operator must is "AND / =".');
}
}
else {
throw new Error('ast.type must is "binary_expr".');
}
}
/**
* json5.stringify( new NodeSQLParser.Parser().astify("").where)
* select * from aa where f1=1 and f2=2 and f3='3' and f4>=4 and f4<3
{
type: 'binary_expr',
operator: 'AND',
left: {
type: 'binary_expr',
operator: 'AND',
left: {
type: 'binary_expr',
operator: 'AND',
left: {
type: 'binary_expr',
operator: 'AND',
left: {
type: 'binary_expr',
operator: '=',
left: {
type: 'column_ref',
table: null,
column: 'f1'
},
right: {
type: 'number',
value: 1
}
},
right: {
type: 'binary_expr',
operator: '=',
left: {
type: 'column_ref',
table: null,
column: 'f2'
},
right: {
type: 'number',
value: 2
}
}
},
right: {
type: 'binary_expr',
operator: '=',
left: {
type: 'column_ref',
table: null,
column: 'f3'
},
right: {
type: 'single_quote_string',
value: '3'
}
}
},
right: {
type: 'binary_expr',
operator: '>=',
left: {
type: 'column_ref',
table: null,
column: 'f4'
},
right: {
type: 'number',
value: 4
}
}
},
right: {
type: 'binary_expr',
operator: '<',
left: {
type: 'column_ref',
table: null,
column: 'f4'
},
right: {
type: 'number',
value: 3
}
}
}
* */
}
function initParamComplex () {
Ext.define('Yvan.ParamComplex', {
extend: 'Ext.panel.Panel',
xtype: 'paramcomplex',
alias: 'widget.paramcomplex',
getSqlExpress: function () {
},
constructor: function (config) {
var reference = config.reference;
var me = this;
var newConfig = __assign(__assign({}, config), { layout: 'border', items: [
{
region: 'west',
width: 280,
border: false,
split: true,
reference: reference + '_tree',
xtype: 'yvtree',
hideRefresh: true,
hideExpand: true,
hideCollapse: true,
listeners: {
itemdblclick: function (sender, record, item, index, e) {
var field = record.get('field');
var defaultValue = record.get('defaultValue');
if (!field) {
return;
}
var tabExpress = me.down('tabpanel');
var sqleditor = me.down('sqleditor');
var expressGrid = me.down('yvgrid');
if (tabExpress.getActiveTab().key !== 'grid') {
// SQL 模式
sqleditor.insertText(field + '=');
}
else {
// 表格模式
expressGrid.appendEditRow({
field: field,
operator: '=',
value: defaultValue,
remark: '',
});
_$2.defer(function () {
gridChanged(me, expressGrid);
});
}
}
},
},
{
region: 'center',
xtype: 'tabpanel',
reference: reference + '_tab',
tabPosition: 'bottom',
listeners: {
afterrender: function (sender) {
var scope = lookupScope(me);
var value = scope.viewModel.get(me.config.bindValue);
// sql 转换为 grid
try {
var list_1 = parseParamToGrid(value);
_$2.defer(function () {
var grid = me.down('yvgrid');
grid.setData(list_1);
});
}
catch (e) {
console.error(e);
msg$1('无法解析SQL语法! 目前只能以 SQL 模式打开,如果在表格中做修改,将会覆盖原语句!');
var tabSql = sender.down('sqleditor');
sender.setActiveTab(tabSql);
}
},
beforetabchange: function (sender, newCard, oldCard, eOpts) {
var scope = lookupScope(me);
var value = scope.viewModel.get(me.config.bindValue);
if (newCard.key === 'grid') {
// sql 转换为 grid
try {
var list_2 = parseParamToGrid(value);
_$2.defer(function () {
var grid = me.down('yvgrid');
grid.setData(list_2);
});
return true;
}
catch (e) {
msg$1('无法解析 SQL 语法! 表格模式只适用于简单语法');
console.error(e);
return false;
}
}
else if (newCard.key === 'sql') {
// grid 转换为 sql
_$2.defer(function () {
var editor = me.down('sqleditor');
editor.setValue(value);
});
return true;
}
}
},
items: [
{
title: '表格模式',
key: 'grid',
xtype: 'yvgrid',
_mode: 'select',
reference: reference + '_grid',
hideFootbar: true,
pagination: false,
tbar: [
{
xtype: 'button',
text: '删除',
iconCls: 'x-fa fa-minus-circle',
cls: 'ext-btn-danger',
bind: {
disabled: '{!' + reference + '_grid.selection}',
},
listeners: {
click: function (sender) {
var grid = sender.up('yvgrid');
removeGridRow(grid);
gridChanged(me, grid);
}
},
},
],
store: {},
listeners: {
editfinish: function (sender) {
gridChanged(me, sender);
},
},
columns: [
{
dataIndex: 'field',
header: '字段', sortable: false, menuDisabled: true,
width: 190,
renderer: function (value, context, record, rowIdx, colIdx, store, view) {
var column = context.column;
var propertyConfig = me.config.propertyConfig;
// 找到 propertyConfig 对应 propertyName 名称的 dict 字典的 dict.text 值
var field = record.get('field');
if (field) {
var idx = _$2.findIndex(propertyConfig, function (p) { return p.field === field; });
if (idx >= 0) {
var meta = propertyConfig[idx];
return meta.text;
}
}
return value;
}
},
{
dataIndex: 'value',
header: '值', sortable: false, menuDisabled: true,
flex: 1,
getEditor: function (record) {
var column = this;
var grid = _$2.get(column, 'ownerCt.grid.ownerGrid');
var propertyConfig = me.config.propertyConfig;
var field = record.get('field');
if (!field) {
// 没有填 propertyName
return;
}
var idx = _$2.findIndex(propertyConfig, function (p) { return p.field === field; });
if (idx < 0) {
console.error('没有找到 field=' + field + ". propertyConfig");
return;
}
var meta = propertyConfig[idx];
if ((record.get('operator') === 'in' || record.get('operator') === 'notIn') && meta.editor.xtype === 'combo') {
return new Ext.grid.CellEditor({
field: __assign(__assign({ dict: meta.dict }, meta.editor), { xtype: 'tagfield' })
});
}
return new Ext.grid.CellEditor({
field: __assign({ dict: meta.dict }, meta.editor)
});
},
renderer: function (valueList, context, record, rowIdx, colIdx, store, view) {
var column = context.column;
var grid = _$2.get(view, 'ownerGrid');
var propertyConfig = me.config.propertyConfig;
// 找到 propertyConfig 对应 propertyName 名称的 dict 字典的 dict.text 值
var field = record.get('field');
if (field) {
var idx = _$2.findIndex(propertyConfig, function (p) { return (p.field) === field; });
if (idx >= 0) {
var meta = propertyConfig[idx];
var dictName = _$2.get(meta, 'dict');
if (dictName && window['DICT_CACHE'][dictName]) {
var dict_1 = window['DICT_CACHE'][dictName];
var valueText_1 = [];
_$2.forEach(_$2.split(valueList, ','), function (value) {
var idxKv = _$2.findIndex(dict_1, function (kv) { return _$2.toString(kv.id) === _$2.toString(value); });
if (idxKv >= 0) {
valueText_1.push(dict_1[idxKv].text);
}
else {
valueText_1.push(value);
}
});
return valueText_1.join(',');
}
}
}
return valueList;
},
},
]
},
{
title: '文本模式',
key: 'sql',
xtype: 'sqleditor',
reference: reference + '_sql',
listeners: {
change: function (sender) {
var scope = lookupScope(me);
// 保存 editor 写入的值
scope.viewModel.set(me.config.bindValue, sender.getValue());
}
}
},
]
}
] });
this.superclass.constructor.call(this, newConfig);
},
initComponent: function () {
// 货位条件树
var me = this;
me.superclass.initComponent.apply(this, arguments);
var tree = this.down('yvtree');
var config = me.config;
tree.setRootNode(buildConfigTree(config.propertyConfig));
},
});
function gridChanged(me, grid) {
var data = grid.getDataRows();
var propertyConfig = me.config.propertyConfig;
var bindValue = me.config.bindValue;
var scope = lookupScope(me);
var sql = parseGridToParam(data);
scope.viewModel.set(bindValue, sql);
}
/**
* 用于从 propertyConfig 解析出树形结构
* { text: '库别分类', field: 'loc_classify', operator: '=', category: '库位属性', editor: {xtype: 'combo'}, dict: 'AREA_CLASSIFY', },
* ->
* {text: '库别分类', field: 'loc_classify', operator: '=', leaf: true},
*/
function buildConfigTree(propertyConfig) {
var root = {
expanded: true,
leaf: false,
children: []
};
var categoryObj = {};
var cfgList = propertyConfig;
_$2.forEach(cfgList, function (cfg) {
var cateNode = categoryObj[cfg.category];
if (!cateNode) {
cateNode = {
text: cfg.category, expanded: true, leaf: false,
children: []
};
categoryObj[cfg.category] = cateNode;
root.children.push(cateNode);
}
cateNode.children.push({
text: cfg.text,
field: cfg.field,
operator: cfg.operator,
defaultValue: cfg.defaultValue,
leaf: true,
});
});
return root;
}
/**
* 将表格变成参数语句 [
* {field: 'f1', value: 1}
* {field: 'f2', value: 2}
* {field: 'f3', value: '3'}
* {field: 'f4', value: 4}
* ]
* ->
* f1=v1, f2=v2
*/
function parseGridToParam(list) {
var sqls = [];
_$2.forEach(list, function (i) {
sqls.push(i.field + '=' + (i.value));
});
return sqls.join('; ');
}
/**
* 将 分号分割的的参数设置 变成表格
* @param param a=1; b=2; c='3'
* @return [
{field: 'a', value: 1}
{field: 'b', value: 2}
{field: 'c', value: '3'}
]
*/
function parseParamToGrid(param) {
if (!param || !_$2.trim(param)) {
return [];
}
var ret = [];
var sp = _$2.split(param, ';');
_$2.forEach(sp, function (v) {
var vi = _$2.indexOf(v, '=');
var field = _$2.trim(v.substr(0, vi));
var value = eval(v.substr(vi + 1));
ret.push({ field: field, value: value });
});
return ret;
}
}
function initSqlEditor$1 () {
Ext.define('com.yvan.studio.SqlEditor', {
extend: 'Ext.panel.Panel',
alias: 'widget.sqleditor',
xtype: 'sqleditor',
layout: 'fit',
border: false,
html: "
",
config: {
value: ''
},
codeChange: undefined,
isChangeFromOuter: false,
setCode: function (value) {
var _this = this;
this.code = value;
this.value = value;
_$2.defer(function () {
_this.isChangeFromOuter = true;
if (_this.editor) {
_this.editor.setValue(value);
}
});
},
getCode: function () {
return this.getValue();
},
updateOptions: function (options) {
if (this.editor && options) {
this.editor.updateOptions(options);
}
},
getValue: function () {
if (!this.editor) {
return this.code;
}
return this.editor.getValue();
},
applyPosition: function () {
var _this = this;
if (this.autoFocusMethod) {
if (this.editor) {
_$2.defer(function () {
if (_this.autoFocusStartLine) {
_this.editor.setPosition({
lineNumber: _this.autoFocusStartLine,
column: _this.autoFocusStartColumn
});
_this.editor.revealLine(_this.autoFocusStartLine); //滚动到特定行
}
_this.editor.focus();
});
delete this.autoFocusMethod;
}
}
this.editor.layout();
},
insertText: function (text) {
var editor = this.editor;
var position = editor.getPosition();
editor.executeEdits('', [
{
range: {
startLineNumber: position.lineNumber,
startColumn: position.column,
endLineNumber: position.lineNumber,
endColumn: position.column
},
text: text
}
]);
},
setValue: function (value, fromEditor) {
this.setCode(value);
var me = this;
if (me.value === value) {
// 值相等,不需要变化
return;
}
if (fromEditor !== true && me.editor) {
// 不是来源于编辑器的变化,才设置编辑器的值
me.editor.setValue(value);
}
// 通知mixins setValue
me.value = value;
me.fireEvent('change', value);
},
initComponent: function () {
var that = this;
this.superclass.initComponent.call(this);
that.on({
resize: function () {
if (that.editor) {
that.editor.layout();
}
},
destory: function () {
if (that.editor) {
that.editor.dispose();
delete that.editor;
}
},
afterrender: function (sender) {
var $dom = $(that.el.dom).find('.editor');
attach_2($dom[0], {
value: that.code
}).then(function (editor) {
that.editor = editor;
that.applyPosition();
that.editor.onDidChangeModelContent(function (e) {
that.fireEvent('change', that.editor, e);
if (typeof that.codeChange === "function" && !that.isChangeFromOuter) {
that.codeChange(that.editor.getValue(), that.name, e);
}
that.isChangeFromOuter = false;
});
});
}
});
}
});
function attach_2(element, opts) {
if (!window['monaco']) {
return;
}
var monaco = window['monaco'];
return new Promise(function (resolve) {
var editor = monaco.editor.create(element, __assign(__assign({}, opts), { language: 'sql', minimap: {
enabled: false
} }));
// editor.addCommand(monaco.KeyMod.Shift | monaco.KeyMod.Alt | monaco.KeyCode.KeyF, function () {
// const sql = editor.getValue()
// if (_.trim(sql).length > 0) {
// editor.setValue(format(sql, {
// indent: ' ',
// uppercase: true,
// }))
// }
// })
editor.onKeyUp(function (e) {
// console.log(e)
if ( /*e.code === 'Enter'||*/e.code === 'Quote') {
editor.trigger('随便写点儿啥', 'editor.action.triggerSuggest', {});
}
});
resolve(editor);
});
}
}
function initJsonEditor$1 () {
Ext.define('com.yvan.studio.JsonEditor', {
extend: 'Ext.panel.Panel',
alias: 'widget.jsoneditor',
xtype: 'jsoneditor',
layout: 'fit',
border: false,
html: "
",
autoFocusMethod: true,
autoFocusStartLine: 0,
autoFocusStartColumn: 0,
codeChange: undefined,
funcArr: [],
modulePage: null,
isChangeFromOuter: false,
name: "",
/**
* 设置代码
*/
setCode: function (value) {
var _this = this;
this.code = value;
_$2.defer(function () {
_this.isChangeFromOuter = true;
if (_this.editor) {
_this.editor.setValue(value);
}
});
},
updateOptions: function (options) {
if (this.editor && options) {
this.editor.updateOptions(options);
}
},
setLanguage: function (lang) {
if (!window['monaco']) {
return;
}
var monaco = window['monaco'];
if (this.editor && lang) {
monaco.editor.setModelLanguage(this.editor.getModel(), lang);
}
},
getCode: function () {
var _a;
return (_a = this.editor) === null || _a === void 0 ? void 0 : _a.getValue();
},
applyPosition: function () {
var _this = this;
if (this.autoFocusMethod) {
if (this.editor) {
_$2.defer(function () {
if (_this.autoFocusStartLine) {
_this.editor.setPosition({
lineNumber: _this.autoFocusStartLine,
column: _this.autoFocusStartColumn
});
_this.editor.revealLine(_this.autoFocusStartLine); //滚动到特定行
}
_this.editor.focus();
});
delete this.autoFocusMethod;
}
}
this.editor.layout();
},
initComponent: function () {
var that = this;
this.superclass.initComponent.apply(this, arguments);
this.on({
resize: function (sender, width, height) {
if (that.editor) {
that.editor.layout();
}
},
destory: function () {
if (that.editor) {
that.editor.dispose();
delete that.editor;
}
},
afterrender: function (sender) {
var $dom = $(that.el.dom).find('.editor');
attach_116($dom[0], {
value: that.code
}).then(function (editor) {
that.editor = editor;
that.applyPosition();
that.editor.onDidChangeModelContent(function (e) {
that.fireEvent('change', that.editor, e);
if (typeof that.codeChange === "function" && !that.isChangeFromOuter) {
that.codeChange(that.editor.getValue(), that.name, e);
}
that.isChangeFromOuter = false;
});
});
}
});
},
});
function attach_116(element, opts) {
if (!window['monaco']) {
return;
}
var monaco = window['monaco'];
return new Promise(function (resolve) {
var editor = monaco.editor.create(element, __assign(__assign({}, opts), { language: 'json', minimap: {
enabled: false
} }));
editor.onKeyUp(function (e) {
// console.log(e)
if ( /*e.code === 'Enter'||*/e.code === 'Quote') {
editor.trigger('随便写点儿啥', 'editor.action.triggerSuggest', {});
}
});
resolve(editor);
});
}
}
function initJsEditor$1 () {
Ext.define('com.yvan.studio.JsEditor', {
extend: 'Ext.panel.Panel',
alias: 'widget.jseditor',
xtype: 'jseditor',
layout: 'fit',
border: false,
html: "
",
autoFocusMethod: true,
autoFocusStartLine: 0,
autoFocusStartColumn: 0,
codeChange: undefined,
funcArr: [],
modulePage: null,
isChangeFromOuter: false,
name: "",
/**
* 设置代码
*/
setCode: function (value) {
var _this = this;
this.code = value;
_$2.defer(function () {
_this.isChangeFromOuter = true;
if (_this.editor) {
_this.editor.setValue(value);
if (_this.name === "controllerEditor") {
_this.funcArr = _this.getAllFunction();
}
}
});
},
getCode: function () {
var _a;
if (!this.editor) {
return this.code;
}
return (_a = this.editor) === null || _a === void 0 ? void 0 : _a.getValue();
},
applyPosition: function () {
var _this = this;
if (this.autoFocusMethod) {
if (this.editor) {
_$2.defer(function () {
if (_this.autoFocusStartLine) {
_this.editor.setPosition({
lineNumber: _this.autoFocusStartLine,
column: _this.autoFocusStartColumn
});
_this.editor.revealLine(_this.autoFocusStartLine); //滚动到特定行
}
_this.editor.focus();
});
delete this.autoFocusMethod;
}
}
this.editor.layout();
},
initComponent: function () {
var that = this;
this.superclass.initComponent.apply(this, arguments);
this.on({
resize: function (sender, width, height) {
if (that.editor) {
that.editor.layout();
}
},
destory: function () {
if (that.editor) {
that.editor.dispose();
delete that.editor;
}
},
afterrender: function () {
var $dom = $(that.el.dom).find('.editor');
attach_1($dom[0], {
value: that.code
}).then(function (editor) {
that.editor = editor;
that.applyPosition();
that.editor.onDidChangeModelContent(function (e) {
that.fireEvent('change', that.editor, e);
if (typeof that.codeChange === "function" && !that.isChangeFromOuter) {
that.codeChange(that.editor.getValue(), that.name, e);
}
that.isChangeFromOuter = false;
});
});
}
});
},
getAllFunction: function () {
var funcArr = [];
var ast = window['YvanUI'].recast.parse(this.code);
if (ast && ast.program && ast.program.body) {
if (Array.isArray(ast.program.body)) {
for (var i = 0; i < ast.program.body.length; i++) {
var m = ast.program.body[i];
if (m.type === "ExportDefaultDeclaration") {
if (m.declaration.type === "ClassDeclaration") {
if (m.declaration.body.type === "ClassBody") {
if (Array.isArray(m.declaration.body.body)) {
for (var j = 0; j < m.declaration.body.body.length; j++) {
var ob = m.declaration.body.body[j];
if (ob.type === "MethodDefinition" && ob.kind === "method") {
var funcItem = { name: ob.key.name, args: [] };
if (Array.isArray(ob.value.params)) {
for (var k = 0; k < ob.value.params.length; k++) {
var p = ob.value.params[k];
funcItem.args.push(p.name);
}
}
funcArr.push(funcItem);
}
}
}
}
}
}
}
}
}
return funcArr;
}
});
var isInited = false;
function attach_1(element, opts) {
if (!window['monaco']) {
return;
}
var monaco = window['monaco'];
return new Promise(function (resolve) {
if (!isInited) {
isInited = true;
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
noSemanticValidation: true,
noSyntaxValidation: false
});
// compiler options
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES2016,
allowNonTsExtensions: true,
});
// extra libraries
var libSource = [
'declare class Facts {',
' /**',
' * Returns the next fact',
' */',
' static next():string',
' static next222():string',
'}',
"\n declare namespace WotuUI {\n export class Text {\n label: string\n }\n\n export function wrapText(n1: string): Text\n export function render(element:HTMLElement, vjson:any): void\n }\n ",
"\n declare module 'fs' {\n function readFileSync(path: string | number, options?: { encoding?: string; flag?: string; } | null): string;\n }\n "
].join('\n');
var libUri = 'file:///index.d.ts';
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri);
// When resolving definitions and references, the editor will try to use created models.
// Creating a model for the library allows "peek definition/references" commands to work with the library.
monaco.editor.createModel(libSource, 'javascript', monaco.Uri.parse(libUri));
}
var editor = monaco.editor.create(element, __assign(__assign({}, opts), { language: 'javascript' }));
resolve(editor);
});
}
}
function initClipboard () {
var cc = Ext.grid.plugin.Clipboard.prototype.constructor;
var initComponent = Ext.grid.plugin.Clipboard.prototype.initComponent;
Ext.grid.plugin.Clipboard.override({
getCellData: function (format, erase) {
var cmp = this.getCmp(), selection = cmp.getSelectionModel().getSelected(), ret = [], isRaw = format === 'raw', isText = format === 'text', viewNode, cell, data, dataIndex, lastRecord, column, record, row, view;
if (selection) {
selection.eachCell(function (cellContext) {
column = cellContext.column;
view = cellContext.column.getView();
record = cellContext.record;
// Do not copy the check column or row numberer column
if (column.ignoreExport && column.xtype !== "checkcolumn") {
return;
}
if (lastRecord !== record) {
lastRecord = record;
ret.push(row = []);
}
dataIndex = column.dataIndex;
// 记录原始数据
var rData = record.data[dataIndex];
if (isRaw) {
data = record.data[dataIndex];
}
else {
// Try to access the view node.
viewNode = view.all.item(cellContext.rowIdx);
// If we could not, it's because it's outside of the rendered block -
// recreate it.
if (!viewNode) {
viewNode = Ext.fly(view.createRowElement(record, cellContext.rowIdx));
}
cell = viewNode.dom.querySelector(column.getCellInnerSelector());
data = cell.innerHTML;
if (isText) {
data = Ext.util.Format.stripTags(data);
}
// 没有找到html text的数据时候给原数据, 主要针对column.xtype === "checkcolumn" 时无法copy到有效值
data = data || rData;
}
row.push(data);
if (erase && dataIndex) {
record.set(dataIndex, null);
}
});
}
// See decode() comment below
return Ext.util.TSV.encode(ret, undefined, null);
},
getCells: function (format, erase) {
var cmp = this.getCmp(), selection = cmp.getSelectionModel().getSelected(), ret = [], dataIndex, lastRecord, record, row;
if (selection) {
selection.eachCell(function (cellContext) {
record = cellContext.record;
if (lastRecord !== record) {
lastRecord = record;
ret.push(row = {
model: record.self,
fields: []
});
}
dataIndex = cellContext.column.dataIndex;
row.fields.push({
name: dataIndex,
value: record.data[dataIndex]
});
if (erase && dataIndex) {
record.set(dataIndex, null);
}
});
}
return ret;
},
getTextData: function (format, erase) {
return this.getCellData(format, erase);
},
putCellData: function (data, format) {
var _a;
var values = Ext.util.TSV.decode(data, undefined, null), row, recCount = values.length, colCount = recCount ? values[0].length : 0, sourceRowIdx, sourceColIdx, view = this.getCmp().getView(), maxRowIdx = view.dataSource.getCount() - 1, maxColIdx = view.getVisibleColumnManager().getColumns().length - 1, selModel = view.getSelectionModel(), selected = selModel.getSelected(), navModel = view.getNavigationModel(), destination = selected.startCell || navModel.getPosition(), dataIndex, destinationStartColumn, dataObject = {};
// If the view is not focused, use the first cell of the selection as the destination.
if (!destination && selected) {
selected.eachCell(function (c) {
destination = c;
return false;
});
}
if (destination) {
// Create a new Context based upon the outermost View.
// NavigationModel works on local views.
// TODO: remove this step when NavModel is fixed to use outermost view in locked grid.
// At that point, we can use navModel.getPosition()
destination = new Ext.grid.CellContext(view).setPosition(destination.record, destination.column);
}
else {
destination = new Ext.grid.CellContext(view).setPosition(0, 0);
}
destinationStartColumn = destination.colIdx;
for (sourceRowIdx = 0; sourceRowIdx < recCount; sourceRowIdx++) {
row = values[sourceRowIdx];
// Collect new values in dataObject
for (sourceColIdx = 0; sourceColIdx < colCount; sourceColIdx++) {
if (!destination.column.initialConfig.editor && destination.column.xtype !== "checkcolumn") {
continue;
}
dataIndex = destination.column.dataIndex;
var editorXtype = (_a = destination.column.editor) === null || _a === void 0 ? void 0 : _a.xtype;
if (dataIndex) {
switch (format) {
// Raw field values
case 'raw':
dataObject[dataIndex] = row[sourceColIdx] === "false" ? false : row[sourceColIdx] === "true" ? true : row[sourceColIdx];
break;
// Textual data with HTML tags stripped
case 'text':
{
if ((editorXtype === "combo" || editorXtype === "combobox") && (typeof destination.column.renderer === "function")) {
// 获取字典原始的value
dataObject[dataIndex] = destination.column.renderer(row[sourceColIdx], true);
}
else {
dataObject[dataIndex] = row[sourceColIdx] === "false" ? false : row[sourceColIdx] === "true" ? true : row[sourceColIdx];
}
break;
}
}
}
// If we are at the end of the destination row, break the column loop.
if (destination.colIdx === maxColIdx) {
break;
}
destination.setColumn(destination.colIdx + 1);
}
// Update the record in one go.
destination.record.set(dataObject);
// If we are at the end of the destination store, break the row loop.
if (destination.rowIdx === maxRowIdx) {
break;
}
// Jump to next row in destination
destination.setPosition(destination.rowIdx + 1, destinationStartColumn);
}
},
putTextData: function (data, format) {
var _a, _b, _c;
var values = Ext.util.TSV.decode(data, undefined, null), view = this.getCmp().getView(), selModel = view.getSelectionModel(), selected = selModel.getSelected();
// 根据复制的行数自动添加新的行
var dataLength = ((_c = (_b = (_a = this.cmp.getStore()) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.length) || 0;
if (selected.startCell.rowIdx + values.length >= dataLength) {
for (var i = 0; i < selected.startCell.rowIdx + values.length - dataLength; i++) {
this.cmp.getStore().add({});
}
}
this.putCellData(data, format);
},
});
}
function initDict$1 () {
var DICT_CACHE = window['DICT_CACHE'];
if (!DICT_CACHE) {
DICT_CACHE = {};
window['DICT_CACHE'] = DICT_CACHE;
}
DICT_CACHE.XTYPE = [
{ id: 'datefield', text: '日期' },
{ id: 'datetimefield', text: '日期时间' },
{ id: 'textfield', text: '文本' },
{ id: 'numberfield', text: '数字' },
{ id: 'combo', text: '下拉框' },
];
DICT_CACHE.operator = [
{ id: '=', text: '=' },
{ id: '>', text: '>' },
{ id: '<', text: '<' },
{ id: '>=', text: '>=' },
{ id: '<=', text: '<=' },
{ id: 'in', text: 'in' },
{ id: 'notIn', text: 'notIn' },
];
DICT_CACHE.GRID_MODE = [
{ id: 'edit1', text: '单机编辑模式' },
{ id: 'edit2', text: '双击编辑模式' },
{ id: 'checkbox', text: '勾选' },
{ id: 'checkonly', text: '只勾选' },
{ id: 'select', text: '行选择模式' },
];
DICT_CACHE.BOTH_SELECT = [
{ id: 'N/A', text: '<无>' },
{ id: 'textfield', text: '文本' },
{ id: 'numberfield', text: '数字框' },
{ id: 'datefield', text: '日期' },
{ id: 'datetimefield', text: '日期时间' },
{ id: 'combo', text: '下拉框' },
{ id: 'combogrid', text: '下拉表' },
{ id: 'checkbox', text: '勾选' },
];
DICT_CACHE.ROW_LAYOUT = [
{ id: 'flex', text: '按权重摆放' },
{ id: 'hbox', text: '按宽度摆放' },
];
DICT_CACHE.GRID_XTYPE = [
{ id: 'N/A', text: '<无>' },
{ id: 'textfield', text: '文本-textfield' },
{ id: 'numberfield', text: '数字框-numberfield' },
{ id: 'datefield', text: '日期-datefield' },
{ id: 'datetimefield', text: '日期时间-datetimefield' },
{ id: 'combo', text: '下拉框-combo' },
{ id: 'combogrid', text: '下拉表-combogrid' },
{ id: 'checkbox', text: '勾选-checkbox' },
];
DICT_CACHE.FORM_XTYPE = [
{ id: 'N/A', text: '<无>' },
{ id: 'textfield', text: '文本-textfield' },
{ id: 'numberfield', text: '数字框-numberfield' },
{ id: 'datefield', text: '日期-datefield' },
{ id: 'datetimefield', text: '日期时间-datetimefield' },
{ id: 'combo', text: '下拉框-combo' },
{ id: 'combogrid', text: '下拉表-combogrid' },
{ id: 'checkbox', text: '勾选-checkbox' },
{ id: 'multiplesearch', text: '多段文本-multiplesearch' },
];
DICT_CACHE.GRID_FORMATTER = [
{ id: 'N/A', text: '默认' },
{ id: 'rownum', text: '序号-rownum' },
{ id: 'button', text: '按钮-button' },
{ id: 'checkbox', text: '勾选-checkbox' },
{ id: 'progres', text: '进度条-progres' },
];
}
function initDesigner () {
Ext.define('com.yvan.studio.designer', {
extend: 'Ext.panel.Panel',
alias: 'widget.designer',
xtype: 'designer',
layout: 'fit',
items: [],
constructor: function (config) {
var self = this;
var newConfig = _$2.defaultsDeep({
// 强制性属性
}, config);
this.superclass.constructor.call(self, newConfig);
},
initComponent: function () {
var me = this;
me.on({
afterrender: function () {
}
});
this.superclass.initComponent.call(me);
}
});
}
var FixClass = /** @class */ (function () {
function FixClass() {
}
FixClass.prototype.fix = function (me, config) {
var _this = this;
if (isDesignMode(me, config)) {
return;
}
if (!config) {
return;
}
var fix = config.fix;
if (!fix) {
return;
}
delete config.fix;
// 这里有个 bug
// 但凡是调用了 this.lookupViewModel() 就会出现绑定不了的情况
// const scope = config.$initParent.lookupReferenceHolder().yvanScope //lookupScope(me)
var scope;
if (config.$initParent) {
// 在面板上的组件
scope = config.$initParent.lookupReferenceHolder().yvanScope; //lookupScope(me)
}
else if (config.column) {
// 在列上的组件
scope = config.column.lookupReferenceHolder().yvanScope; //lookupScope(me)
}
if (_$2.isArray(fix)) {
_$2.each(fix, function (f) {
var fn = lookupFn(scope, f);
fn.call(_this, me, config);
});
}
else if (_$2.isString(fix)) {
var fn = lookupFn(scope, fix);
fn.call(this, me, config);
}
};
__decorate([
baseConfigProcess(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", void 0)
], FixClass.prototype, "fix", null);
return FixClass;
}());
function init$2() {
// 引入 filters 过滤插件
Ext.require([
'Ext.grid.filters.Filters'
]);
// 启用 tooltip 快捷提示
Ext.QuickTips.init();
// 定义日期格式化方法
if (Ext.util && Ext.util.Format) {
Ext.apply(Ext.util.Format, {
dateFormat: 'Y-m-d'
});
}
Ext.form.field.Display.override({
cls: 'yvan-display-field',
labelAlign: 'right'
});
Ext.define("Ext.locale.zh_CN.picker.Date", {
override: "Ext.picker.Date",
format: "Y-m-d",
});
Ext.define("Ext.locale.zh_CN.form.field.Date", {
override: "Ext.form.field.Date",
format: "Y-m-d",
});
Ext.define("Ext.locale.zh_CN.grid.PropertyColumnModel", {
override: "Ext.grid.PropertyColumnModel",
format: "Y-m-d",
});
Ext.define("Ext.locale.zh_CN.view.AbstractView", {
override: "Ext.view.AbstractView",
loadingText: "读取中..."
});
Ext.LoadMask.prototype.msg = '请稍后...';
Ext.define("Ext.locale.zh_CN.grid.header.Container", {
override: "Ext.grid.header.Container",
sortClearText: '不排序',
sortAscText: "正序",
sortDescText: "倒序",
lockText: "锁定列",
unlockText: "解除锁定",
columnsText: "字段隐藏"
});
Ext.define("Ext.locale.zh_CN.grid.filters.filter.Date", {
override: "Ext.grid.filters.filter.Date",
fields: {
lt: { text: '之前' },
gt: { text: '之后' },
eq: { text: '相等' },
},
// Defaults to Ext.Date.defaultFormat
dateFormat: null
});
// Ext.grid.locking.Lockable.prototype.unlockText = '解锁'
// Ext.grid.locking.Lockable.prototype.lockText = '锁定'
// Ext.grid.filters.Filters.prototype.menuFilterText = "过滤"
Ext.define("Ext.locale.zh_CN.grid.locking.Lockable", {
override: "Ext.grid.locking.Lockable",
lockText: "锁定",
unlockText: '解锁',
});
Ext.define("Ext.locale.zh_CN.grid.filters.Filters", {
override: "Ext.grid.filters.Filters",
menuFilterText: "过滤"
});
Ext.define("Ext.locale.zh_CN.grid.filters.filter.Boolean", {
override: "Ext.grid.filters.filter.Boolean",
yesText: "已钩选",
noText: "未勾选"
});
Ext.define("Ext.locale.zh_CN.grid.filters.filter.String", {
override: "Ext.grid.filters.filter.String",
emptyText: "输入过滤文本..."
});
Ext.define("Ext.locale.zh_CN.grid.filters.filter.Number", {
override: "Ext.grid.filters.filter.Number",
emptyText: "输入数字..."
});
Ext.define("Ext.locale.zh_CN.toolbar.Paging", {
override: "Ext.PagingToolbar",
beforePageText: "第",
// update
afterPageText: "/ {0} 页",
// update
firstText: "第一页",
prevText: "上一页",
// update
nextText: "下一页",
lastText: "最后页",
refreshText: "刷新",
displayMsg: "总共 {2} 条",
// update
emptyMsg: '没有数据'
});
/**
* 改变事件的获取方式.
* 具体见: ext-all-debug.js:23216 addListener
* https://docs.sencha.com/extjs/6.6.0/classic/Ext.util.Observable.html#method-addListener
* https://docs.sencha.com/extjs/6.6.0/classic/src/Observable.js.html#Ext.mixin.Observable-method-addListener
*/
var _doAddListener = Ext.mixin.Observable.prototype.doAddListener;
Ext.mixin.Observable.prototype.doAddListener = function (ename, fn, scope, options, order, caller, manager) {
if (typeof fn === 'string' &&
(_$2.startsWith(fn, 'scope.') ||
_$2.startsWith(fn, 'system.') ||
_$2.startsWith(fn, 'format.'))) {
scope = lookupScope(this);
if (isDesignMode(scope, undefined)) {
fn = Ext.emptyFn;
}
else {
// console.log('doAddListener', ename, fn, scope, options, order, caller, manager)
// const vm = this.lookupViewModel()
// if (vm && vm.yvanScope) {
// scope = vm.yvanScope
// fn = scope[fn.substr('scope.'.length)]
// }
fn = lookupFn(scope, fn, this);
}
}
_doAddListener.call(this, ename, fn, scope, options, order, caller, manager);
};
// 将 SystemLib 扩展到 window.system 下
if (!window['system']) {
window['system'] = {};
}
_$2.extend(window['system'], SystemLib);
_$2.extend(window['system'], {
showGridRowDetail: showGridRowDetail
});
Ext.apply(Ext.util.Format, {
// 百分比
percentRenderer: function (v, rd, model) {
if (!v) {
v = 0;
}
if (typeof v === 'string') {
v = parseInt(v);
}
var valueString = v.toFixed(2);
var valueFixed = v > 100 ? 100 : v;
valueFixed = valueFixed < 0 ? 0 : valueFixed;
var cls = '';
if (v < 90) {
cls = 'danger';
}
else if (v < 100) {
cls = 'warning';
}
else {
cls = 'success';
}
return Ext.String
.format(
// '