@steedos-widgets/sortable 1.3.9 → 1.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20156,6 +20156,53 @@
20156
20156
  /** Used to infer the `Object` constructor. */
20157
20157
  funcToString.call(Object);
20158
20158
 
20159
+ /*
20160
+ * @Author: baozhoutao@steedos.com
20161
+ * @Date: 2022-08-16 17:02:08
20162
+ * @LastEditors: baozhoutao@steedos.com
20163
+ * @LastEditTime: 2023-06-20 13:50:15
20164
+ * @Description:
20165
+ */
20166
+
20167
+
20168
+ const Router = {
20169
+ getTabDisplayAs(tab_id){
20170
+ var urlSearch = new URLSearchParams(document.location.search);
20171
+ if(urlSearch.has('display')){
20172
+ return urlSearch.get('display')
20173
+ }
20174
+ const key = `tab_${tab_id}_display`;
20175
+ // const key = `page_display`;
20176
+ const value = localStorage.getItem(key);
20177
+ return value ? value : 'grid'
20178
+ },
20179
+
20180
+ setTabDisplayAs(tab_id, displayAs){
20181
+ const key = `tab_${tab_id}_display`;
20182
+ localStorage.setItem(key, displayAs);
20183
+ },
20184
+ getAppPath({formFactor, appId}){
20185
+ return `/app/${appId}`;
20186
+ },
20187
+ getPagePath(){
20188
+ //TODO
20189
+ },
20190
+ getObjectListViewPath({formFactor, appId, objectName, listViewName}){
20191
+ return `/app/${appId}/${objectName}/grid/${listViewName}`;
20192
+ },
20193
+ getObjectDetailPath(props){
20194
+ const {formFactor, appId, objectName, recordId, listViewName, _templateType} = props;
20195
+ if(_templateType === 'JavaScript'){
20196
+ return `/app/${appId}/${objectName}/view/${recordId}?side_object=<%=item.objectName%>&side_listview_id=<%=item.listName%>`;
20197
+ }
20198
+ return `/app/${appId}/${objectName}/view/${recordId}?side_object=\${objectName}&side_listview_id=\${listName}`;
20199
+ },
20200
+ getObjectRelatedViewPath({formFactor, appId, masterObjectName, masterRecordId, objectName, foreignKey}){
20201
+ return `/app/${appId}/${masterObjectName}/${masterRecordId}/${objectName}/grid?related_field_name=${foreignKey}`;
20202
+ },
20203
+
20204
+ };
20205
+
20159
20206
  const getBuilderContext = ()=>{
20160
20207
  if(typeof window === "undefined"){
20161
20208
  return {};
@@ -20230,437 +20277,109 @@
20230
20277
  return defaultRootUrl || '';
20231
20278
  }
20232
20279
 
20233
- /*
20234
- * @Author: baozhoutao@steedos.com
20235
- * @Date: 2022-08-16 17:02:08
20236
- * @LastEditors: baozhoutao@steedos.com
20237
- * @LastEditTime: 2023-06-20 13:50:15
20238
- * @Description:
20239
- */
20240
-
20241
-
20242
- const Router = {
20243
- getTabDisplayAs(tab_id){
20244
- var urlSearch = new URLSearchParams(document.location.search);
20245
- if(urlSearch.has('display')){
20246
- return urlSearch.get('display')
20247
- }
20248
- const key = `tab_${tab_id}_display`;
20249
- // const key = `page_display`;
20250
- const value = localStorage.getItem(key);
20251
- return value ? value : 'grid'
20252
- },
20253
-
20254
- setTabDisplayAs(tab_id, displayAs){
20255
- const key = `tab_${tab_id}_display`;
20256
- localStorage.setItem(key, displayAs);
20257
- },
20258
- getAppPath({formFactor, appId}){
20259
- return `/app/${appId}`;
20260
- },
20261
- getPagePath(){
20262
- //TODO
20263
- },
20264
- getObjectListViewPath({formFactor, appId, objectName, listViewName}){
20265
- return `/app/${appId}/${objectName}/grid/${listViewName}`;
20266
- },
20267
- getObjectDetailPath(props){
20268
- const {formFactor, appId, objectName, recordId, listViewName, _templateType} = props;
20269
- if(_templateType === 'JavaScript'){
20270
- return `/app/${appId}/${objectName}/view/${recordId}?side_object=<%=item.objectName%>&side_listview_id=<%=item.listName%>`;
20280
+ async function getFieldsTemplate(fields, display){
20281
+ let expandFields = [];
20282
+ if(display != false){
20283
+ display = true;
20284
+ }
20285
+ let fieldsName = ['_id'];
20286
+ let displayFields = [];
20287
+ let fieldsArr = [];
20288
+ if(lodash.exports.isArray(fields)){
20289
+ fieldsArr = fields;
20290
+ }else {
20291
+ fieldsArr = lodash.exports.values(fields);
20292
+ }
20293
+ for (const field of fieldsArr) {
20294
+ //graphql 的 ui\display 中使用的字段需要先在query中查询. 否则会返回null
20295
+ if(field.expand){
20296
+ expandFields.push(field);
20297
+ }else {
20298
+ if(field.name.indexOf('.') < 0){
20299
+ if(display && (field.type == 'lookup' || field.type == 'master_detail')){
20300
+ fieldsName.push(`${field.name}`);
20301
+ displayFields.push(`${field.name}`);
20302
+ }else {
20303
+ fieldsName.push( field.alias ? `${field.alias}:${field.name}` : field.name);
20304
+ }
20305
+ if(lodash.exports.includes(['time','date','datetime','boolean','number','currency'], field.type)){
20306
+ fieldsName.push(`${field.name}`);
20307
+ }
20308
+ if(lodash.exports.includes(['percent','time','filesize','date','datetime','boolean','number','currency', 'select', 'file', 'image', 'avatar', 'formula', 'summary', 'object', 'grid'], field.type)){
20309
+ displayFields.push(`${field.name}`);
20310
+ }
20311
+ }else {
20312
+ objectFieldName = field.name.split('.')[0];
20313
+ fieldsName.push(objectFieldName);
20314
+ displayFields.push(objectFieldName);
20315
+ }
20271
20316
  }
20272
- return `/app/${appId}/${objectName}/view/${recordId}?side_object=\${objectName}&side_listview_id=\${listName}`;
20273
- },
20274
- getObjectRelatedViewPath({formFactor, appId, masterObjectName, masterRecordId, objectName, foreignKey}){
20275
- return `/app/${appId}/${masterObjectName}/${masterRecordId}/${objectName}/grid?related_field_name=${foreignKey}`;
20276
- },
20277
-
20278
- };
20279
-
20280
- /*
20281
- * @Author: baozhoutao@steedos.com
20282
- * @Date: 2022-07-20 16:29:22
20283
- * @LastEditors: liaodaxue
20284
- * @LastEditTime: 2023-09-11 17:19:53
20285
- * @Description:
20286
- */
20287
-
20288
- function getImageFieldUrl(url) {
20289
- if (window.Meteor && window.Meteor.isCordova != true) {
20290
- // '//'的位置
20291
- const doubleSlashIndex = url.indexOf('//');
20292
- const urlIndex = url.indexOf('/', doubleSlashIndex + 2);
20293
- const rootUrl = url.substring(urlIndex);
20294
- return rootUrl;
20295
- }
20296
- return url;
20297
- }
20317
+ }
20298
20318
 
20299
- if(typeof window != 'undefined'){
20300
- window.getImageFieldUrl = getImageFieldUrl;
20301
- }
20319
+ displayFields = lodash.exports.uniq(displayFields);
20320
+ fieldsName = lodash.exports.uniq(fieldsName);
20321
+ let expandFieldsQuery = "";
20322
+ if(expandFields.length > 0){
20323
+ lodash.exports.each(expandFields, function(field){
20324
+ expandFieldsQuery = expandFieldsQuery + `${field.expandInfo.fieldName}__expand{${field.expandInfo.displayName}}`;
20325
+ });
20326
+ }
20302
20327
 
20303
- function getContrastColor(bgColor) {
20304
- var backgroundColor = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor;
20305
- var r = parseInt(backgroundColor.substr(0, 2), 16);
20306
- var g = parseInt(backgroundColor.substr(2, 2), 16);
20307
- var b = parseInt(backgroundColor.substr(4, 2), 16);
20308
- var brightness = (r * 299 + g * 587 + b * 114) / 1000;
20309
- return brightness < 128 ? "#ffffff" : "#000000";
20328
+ if(displayFields.length > 0){
20329
+ return `${fieldsName.join(',')},${expandFieldsQuery},_display:_ui{${displayFields.join(',')}}`;
20330
+ }
20331
+ return lodash.exports.trimEnd(`${fieldsName.join(' ')},${expandFieldsQuery}`, ",")
20310
20332
  }
20311
20333
 
20312
- function getLookupListView(refObjectConfig) {
20313
- if(!refObjectConfig){
20314
- return null;
20315
- }
20316
- const listNameAll = "all";
20317
- const listNameLookup = "lookup";
20318
- let listViewAll, listViewLookup;
20334
+ async function getFindQuery(object, recordId, fields, options){
20335
+ let limit = options.limit || 10;
20336
+ let queryOptions = `(top: ${limit})`;
20337
+ if(recordId){
20338
+ queryOptions = `(filters:["_id", "=", "${recordId}"], top: ${limit})`;
20339
+ }
20340
+ let alias = "data";
20341
+ if(options){
20342
+ if(options.alias){
20343
+ alias = options.alias;
20344
+ }
20319
20345
 
20320
- _.each(
20321
- refObjectConfig.list_views,
20322
- (view, name) => {
20323
- if (name === listNameAll) {
20324
- listViewAll = view;
20325
- if(!listViewAll.name){
20326
- listViewAll.name = name;
20346
+ if(options.filters){
20347
+ queryOptions = `(filters:${options.filters})`;
20327
20348
  }
20328
- }
20329
- else if (name === listNameLookup) {
20330
- listViewLookup = view;
20331
- if(!listViewLookup.name){
20332
- listViewLookup.name = name;
20349
+ if(options.queryOptions){
20350
+ queryOptions = `(${options.queryOptions})`;
20333
20351
  }
20334
- }
20335
20352
  }
20336
- );
20337
- let listView = listViewLookup || listViewAll;
20338
- return listView;
20339
- }
20340
-
20341
- function getNumberTpl(field){
20342
- return `<span>\${_display.${field.name}}</span>`
20343
- }
20344
-
20345
- function getTimeTpl(field){
20346
- return `<span>\${_display.${field.name}}</span>`
20347
- }
20348
-
20349
- function getDateTpl(field){
20350
- return `<span>\${_display.${field.name}}</span>`
20351
- }
20353
+ var treeFields = '';
20354
+ if(object.enable_tree && lodash.exports.includes(lodash.exports.keys(object.fields), 'parent') && lodash.exports.includes(lodash.exports.keys(object.fields), 'children')){
20355
+ treeFields = ',parent,children';
20356
+ }
20352
20357
 
20358
+ var cfsFields = '';
20359
+ if(object.name === 'cms_files'){
20360
+ cfsFields = ',versions';
20361
+ }
20353
20362
 
20354
- function getDateTimeTpl(field){
20355
- return `<span>\${_display.${field.name}}</span>`
20356
- }
20363
+ const countQuery = options.count === false ? "" : `,count:${object.name}__count(filters:{__filters})`;
20364
+ // const moreQuerie = options.moreQueries?.length ? ("," + options.moreQueries.map(function(item){
20365
+ // // 把最外层的{}去除
20366
+ // return item.replace(/^{/,"").replace(/}$/,"");
20367
+ // }).join(",")) : "";
20357
20368
 
20358
- function getUiFieldTpl(field){
20359
- return `<span>\${_display.${field.name}}</span>`
20369
+ return {
20370
+ orderBy: "${orderBy}",
20371
+ orderDir: "${orderDir}",
20372
+ pageNo: "${page}",
20373
+ pageSize: "${perPage}",
20374
+ query: `{${alias}:${object.name}${queryOptions}{${await getFieldsTemplate(fields, options.expand)}${treeFields}${cfsFields}}${countQuery}}`
20375
+ }
20360
20376
  }
20361
20377
 
20362
- function getUiFileSizeTpl(field){
20363
- return `<span>\${_display.${field.name}}</span>`
20364
- }
20365
-
20366
- //TODO 处理name字段
20367
- async function getRefObjectNameFieldName(field){
20368
- const refUiSchema = await getUISchema(field.reference_to);
20369
- const NAME_FIELD_KEY = refUiSchema.NAME_FIELD_KEY || 'name';
20370
- return NAME_FIELD_KEY;
20371
- }
20372
-
20373
- function getSelectTpl(field){
20374
- return `<span>\${_display.${field.name}}</span>`
20375
- }
20376
- function getSelectMap(selectOptions){
20377
- let map = {};
20378
- lodash.exports.forEach(selectOptions,(option)=>{
20379
- const optionValue = option.value + '';
20380
- const optionColor = option.color + '';
20381
- if(optionColor){
20382
- const background = optionColor.charAt(0) === '#' ? optionColor : '#'+optionColor;
20383
- const color = getContrastColor(background);
20384
- const optionColorStyle = 'background:'+background+';color:'+color+';line-height:1.5rem';
20385
- map[optionValue] = `<span class="rounded-xl px-2 py-1" style='${optionColorStyle}'>${option.label}</span>`;
20386
- }else {
20387
- map[optionValue] = option.label;
20388
- }
20389
- });
20390
- return map;
20391
- }
20392
-
20393
- function getNameTplUrl(field, ctx){
20394
- if(ctx.objectName === 'cms_files'){
20395
- return `\${context.rootUrl}/api/files/files/\${versions[0]}?download=true`
20396
- }
20397
- const href = Router.getObjectDetailPath({
20398
- ...ctx, formFactor: ctx.formFactor, appId: "${appId}", objectName: ctx.objectName || "${objectName}", recordId: `\${${ctx.idFieldName}}`
20399
- });
20400
- return href;
20401
- }
20402
-
20403
- function getNameTpl(field, ctx){
20404
- const href = getNameTplUrl(field, ctx);
20405
- let linkTarget = "";
20406
- if(ctx && ctx.isLookup){
20407
- linkTarget = "target='_blank'";
20408
- }
20409
- return `<a href="${href}" ${linkTarget}>\${${field.name}}</a>`
20410
- }
20411
-
20412
- function getRelatedFieldTpl(field, ctx){
20413
- let tpl = '';
20414
- if(!field.reference_to && (field.optionsFunction || field._optionsFunction || field.options)){
20415
- if(field.isTableField){
20416
- return `\${${field.name}}`
20417
- }else {
20418
- return `\${${field.name}__label}`
20419
- }
20420
- }
20421
-
20422
- let linkTarget = "";
20423
- if(ctx && ctx.isLookup){
20424
- linkTarget = "target='_blank'";
20425
- }
20426
-
20427
- const onlyDisplayLookLabel = ctx.onlyDisplayLookLabel;
20428
-
20429
- let fieldDataStrTpl = `data._display.${field.name}`;
20430
-
20431
- if(field.isTableField){
20432
- fieldDataStrTpl = `data.${field.name}`;
20433
- }
20434
-
20435
- if(_.isString(field.reference_to) || !field.reference_to){
20436
- if(field.multiple){
20437
- let labelTpl = `<%=item.label%>`;
20438
- if(!onlyDisplayLookLabel){
20439
- const href = Router.getObjectDetailPath({
20440
- formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
20441
- });
20442
- labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
20443
- }
20444
- tpl = `
20445
- <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item,index) { %> <% if(index>0 && index<${fieldDataStrTpl}.length){ %> , <% } %> ${labelTpl} <% }); %><% } %>
20446
- `;
20447
- }else {
20448
- let labelTpl = `\${_display.${field.name}.label}`;
20449
- let objectNameTpl = `\${_display.${field.name}.objectName}`;
20450
- let recordIdTpl = `\${_display.${field.name}.value}`;
20451
- if(field.isTableField){
20452
- labelTpl = `\${${field.name}.label}`;
20453
- objectNameTpl = `\${${field.name}.objectName}`;
20454
- recordIdTpl = `\${${field.name}.value}`;
20455
- }
20456
- if(!onlyDisplayLookLabel){
20457
- const href = Router.getObjectDetailPath({
20458
- formFactor: ctx.formFactor, appId: "${appId}", objectName: `${objectNameTpl}`, recordId: `${recordIdTpl}`
20459
- });
20460
- labelTpl = `<a href="${href}" ${linkTarget}>${labelTpl}</a>`;
20461
- }
20462
- tpl = labelTpl;
20463
- }
20464
-
20465
-
20466
- }else {
20467
- let labelTpl = `<%=item.label%>`;
20468
- if(!onlyDisplayLookLabel){
20469
- const href = Router.getObjectDetailPath({
20470
- formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
20471
- });
20472
- labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
20473
- }
20474
- tpl = `
20475
- <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item) { %> ${labelTpl} <% }); %><% } %>
20476
- `;
20477
- }
20478
- return tpl
20479
- }
20480
-
20481
- async function getLookupTpl(field, ctx){
20482
- if(!field.reference_to){
20483
- return getSelectTpl(field)
20484
- }
20485
- const NAME_FIELD_KEY = await getRefObjectNameFieldName(field);
20486
- if(field.multiple){
20487
- const href = Router.getObjectDetailPath({
20488
- formFactor: ctx.formFactor, appId: ctx.appId, objectName: field.reference_to, recordId: `<%=item._id%>`, _templateType: "JavaScript"
20489
- });
20490
- return `
20491
- <% if (data.${field.name} && data.${field.name}.length) { %><% data.${field.name}.forEach(function(item) { %> <a href="${href}"><%=item.${NAME_FIELD_KEY}%></a> <% }); %><% } %>
20492
- `
20493
- }else {
20494
- const href = Router.getObjectDetailPath({
20495
- formFactor: ctx.formFactor, appId: ctx.appId, objectName: field.reference_to, recordId: `\${${field.name}._id}`
20496
- });
20497
- return `<a href="${href}">\${${field.name}.${NAME_FIELD_KEY}}</a>`
20498
- }
20499
-
20500
- }
20501
-
20502
- function getSwitchTpl(field){
20503
- let fieldDataStrTpl = `data._display.${field.name}`;
20504
- if(field.isTableField){
20505
- fieldDataStrTpl = `data.${field.name}`;
20506
- }
20507
- return `<% if (data.${field.name}) { %>
20508
- <span class="slds-icon_container slds-icon-utility-check slds-current-color" title="<%=${fieldDataStrTpl}%>">
20509
- <span ><%= ${fieldDataStrTpl} === "√" ? "<svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' class='w-4 h-4'><path stroke-linecap='round' stroke-linejoin='round' d='M4.5 12.75l6 6 9-13.5' /></svg>" : ${fieldDataStrTpl} %></span>
20510
- </span>
20511
- <% } %>`
20512
- }
20513
-
20514
- function getPasswordTpl(field){
20515
- return `<% if (data.${field.name}) { %>
20516
- <span>······</span>
20517
- <% } %>`
20518
- }
20519
-
20520
- function getLocationTpl(field){
20521
- return `\${${field.name} ? ${field.name}.address : ''}`
20522
- }
20523
-
20524
- async function getFieldTpl (field, options){
20525
- if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLookLabel){
20526
- return getNameTpl(field, options)
20527
- }
20528
- switch (field.type) {
20529
- case 'password':
20530
- return getPasswordTpl(field);
20531
- case 'boolean':
20532
- return getSwitchTpl(field);
20533
- case 'toggle':
20534
- return getSwitchTpl(field);
20535
- case 'select':
20536
- return getSelectTpl(field);
20537
- case 'time':
20538
- return getTimeTpl(field);
20539
- case 'date':
20540
- return getDateTpl(field);
20541
- case 'datetime':
20542
- return getDateTimeTpl(field);
20543
- case 'lookup':
20544
- return await getRelatedFieldTpl(field, options);
20545
- case 'master_detail':
20546
- return await getRelatedFieldTpl(field, options);
20547
- case 'location':
20548
- return await getLocationTpl(field);
20549
- case 'number':
20550
- case 'currency':
20551
- return await getNumberTpl(field);
20552
- case 'percent':
20553
- case 'formula':
20554
- case 'summary':
20555
- return getUiFieldTpl(field)
20556
- case 'filesize':
20557
- return getUiFileSizeTpl(field)
20558
- }
20559
- }
20560
-
20561
- async function getFieldsTemplate(fields, display){
20562
- let expandFields = [];
20563
- if(display != false){
20564
- display = true;
20565
- }
20566
- let fieldsName = ['_id'];
20567
- let displayFields = [];
20568
- let fieldsArr = [];
20569
- if(lodash.exports.isArray(fields)){
20570
- fieldsArr = fields;
20571
- }else {
20572
- fieldsArr = lodash.exports.values(fields);
20573
- }
20574
- for (const field of fieldsArr) {
20575
- //graphql 的 ui\display 中使用的字段需要先在query中查询. 否则会返回null
20576
- if(field.expand){
20577
- expandFields.push(field);
20578
- }else {
20579
- if(field.name.indexOf('.') < 0){
20580
- if(display && (field.type == 'lookup' || field.type == 'master_detail')){
20581
- fieldsName.push(`${field.name}`);
20582
- displayFields.push(`${field.name}`);
20583
- }else {
20584
- fieldsName.push( field.alias ? `${field.alias}:${field.name}` : field.name);
20585
- }
20586
- if(lodash.exports.includes(['time','date','datetime','boolean','number','currency'], field.type)){
20587
- fieldsName.push(`${field.name}`);
20588
- }
20589
- if(lodash.exports.includes(['percent','time','filesize','date','datetime','boolean','number','currency', 'select', 'file', 'image', 'avatar', 'formula', 'summary', 'object', 'grid'], field.type)){
20590
- displayFields.push(`${field.name}`);
20591
- }
20592
- }else {
20593
- objectFieldName = field.name.split('.')[0];
20594
- fieldsName.push(objectFieldName);
20595
- displayFields.push(objectFieldName);
20596
- }
20597
- }
20598
- }
20599
-
20600
- displayFields = lodash.exports.uniq(displayFields);
20601
- fieldsName = lodash.exports.uniq(fieldsName);
20602
- let expandFieldsQuery = "";
20603
- if(expandFields.length > 0){
20604
- lodash.exports.each(expandFields, function(field){
20605
- expandFieldsQuery = expandFieldsQuery + `${field.expandInfo.fieldName}__expand{${field.expandInfo.displayName}}`;
20606
- });
20607
- }
20608
-
20609
- if(displayFields.length > 0){
20610
- return `${fieldsName.join(',')},${expandFieldsQuery},_display:_ui{${displayFields.join(',')}}`;
20611
- }
20612
- return lodash.exports.trimEnd(`${fieldsName.join(' ')},${expandFieldsQuery}`, ",")
20613
- }
20614
-
20615
- async function getFindQuery(object, recordId, fields, options){
20616
- let limit = options.limit || 10;
20617
- let queryOptions = `(top: ${limit})`;
20618
- if(recordId){
20619
- queryOptions = `(filters:["_id", "=", "${recordId}"], top: ${limit})`;
20620
- }
20621
- let alias = "data";
20622
- if(options){
20623
- if(options.alias){
20624
- alias = options.alias;
20625
- }
20626
-
20627
- if(options.filters){
20628
- queryOptions = `(filters:${options.filters})`;
20629
- }
20630
- if(options.queryOptions){
20631
- queryOptions = `(${options.queryOptions})`;
20632
- }
20633
- }
20634
- var treeFields = '';
20635
- if(object.enable_tree && lodash.exports.includes(lodash.exports.keys(object.fields), 'parent') && lodash.exports.includes(lodash.exports.keys(object.fields), 'children')){
20636
- treeFields = ',parent,children';
20637
- }
20638
-
20639
- var cfsFields = '';
20640
- if(object.name === 'cms_files'){
20641
- cfsFields = ',versions';
20642
- }
20643
-
20644
- const countQuery = options.count === false ? "" : `,count:${object.name}__count(filters:{__filters})`;
20645
- // const moreQuerie = options.moreQueries?.length ? ("," + options.moreQueries.map(function(item){
20646
- // // 把最外层的{}去除
20647
- // return item.replace(/^{/,"").replace(/}$/,"");
20648
- // }).join(",")) : "";
20649
-
20650
- return {
20651
- orderBy: "${orderBy}",
20652
- orderDir: "${orderDir}",
20653
- pageNo: "${page}",
20654
- pageSize: "${perPage}",
20655
- query: `{${alias}:${object.name}${queryOptions}{${await getFieldsTemplate(fields, options.expand)}${treeFields}${cfsFields}}${countQuery}}`
20656
- }
20657
- }
20658
-
20659
- function getApi$2 (isMobile){
20660
- if(isMobile);else {
20661
- // return __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + "/graphql"
20662
- return `\${context.rootUrl}/graphql?reload=\${additionalFilters}`
20663
- }
20378
+ function getApi$2 (isMobile){
20379
+ if(isMobile);else {
20380
+ // return __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + "/graphql"
20381
+ return `\${context.rootUrl}/graphql?reload=\${additionalFilters}`
20382
+ }
20664
20383
  }
20665
20384
 
20666
20385
  var frontend_field_group_generalization$1 = "General";
@@ -21113,6 +20832,67 @@
21113
20832
  }
21114
20833
  }
21115
20834
 
20835
+ /*
20836
+ * @Author: baozhoutao@steedos.com
20837
+ * @Date: 2022-07-20 16:29:22
20838
+ * @LastEditors: liaodaxue
20839
+ * @LastEditTime: 2023-09-11 17:19:53
20840
+ * @Description:
20841
+ */
20842
+
20843
+ function getImageFieldUrl(url) {
20844
+ if (window.Meteor && window.Meteor.isCordova != true) {
20845
+ // '//'的位置
20846
+ const doubleSlashIndex = url.indexOf('//');
20847
+ const urlIndex = url.indexOf('/', doubleSlashIndex + 2);
20848
+ const rootUrl = url.substring(urlIndex);
20849
+ return rootUrl;
20850
+ }
20851
+ return url;
20852
+ }
20853
+
20854
+ if(typeof window != 'undefined'){
20855
+ window.getImageFieldUrl = getImageFieldUrl;
20856
+ }
20857
+
20858
+ function getContrastColor(bgColor) {
20859
+ var backgroundColor = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor;
20860
+ var r = parseInt(backgroundColor.substr(0, 2), 16);
20861
+ var g = parseInt(backgroundColor.substr(2, 2), 16);
20862
+ var b = parseInt(backgroundColor.substr(4, 2), 16);
20863
+ var brightness = (r * 299 + g * 587 + b * 114) / 1000;
20864
+ return brightness < 128 ? "#ffffff" : "#000000";
20865
+ }
20866
+
20867
+ function getLookupListView(refObjectConfig) {
20868
+ if(!refObjectConfig){
20869
+ return null;
20870
+ }
20871
+ const listNameAll = "all";
20872
+ const listNameLookup = "lookup";
20873
+ let listViewAll, listViewLookup;
20874
+
20875
+ _.each(
20876
+ refObjectConfig.list_views,
20877
+ (view, name) => {
20878
+ if (name === listNameAll) {
20879
+ listViewAll = view;
20880
+ if(!listViewAll.name){
20881
+ listViewAll.name = name;
20882
+ }
20883
+ }
20884
+ else if (name === listNameLookup) {
20885
+ listViewLookup = view;
20886
+ if(!listViewLookup.name){
20887
+ listViewLookup.name = name;
20888
+ }
20889
+ }
20890
+ }
20891
+ );
20892
+ let listView = listViewLookup || listViewAll;
20893
+ return listView;
20894
+ }
20895
+
21116
20896
  /*
21117
20897
  * @Author: baozhoutao@steedos.com
21118
20898
  * @Date: 2022-11-01 15:51:00
@@ -23828,7 +23608,7 @@ crudService && crudService.setData({showFieldsFilter: toShowFieldsFilter});
23828
23608
  if(refObjectConfig.name === 'organizations'){
23829
23609
  labelFieldName = 'name';
23830
23610
  }
23831
- pickerSchema = await getTableSchema$1(tableFields, {
23611
+ pickerSchema = await getTableSchema(tableFields, {
23832
23612
  labelFieldName,
23833
23613
  top: top,
23834
23614
  isLookup: true,
@@ -24318,7 +24098,7 @@ crudService && crudService.setData({showFieldsFilter: toShowFieldsFilter});
24318
24098
  actions: false
24319
24099
  });
24320
24100
  }else {
24321
- pickerSchema = await getTableSchema$1(tableFields, {
24101
+ pickerSchema = await getTableSchema(tableFields, {
24322
24102
  labelFieldName: refObjectConfig.NAME_FIELD_KEY,
24323
24103
  top: top,
24324
24104
  isLookup: true,
@@ -25067,295 +24847,907 @@ crudService && crudService.setData({showFieldsFilter: toShowFieldsFilter});
25067
24847
  return value; // 切换到数字之后的默认值
25068
24848
  }
25069
24849
  }
25070
- };
25071
- break;
25072
- case 'avatar':
25073
- convertData = getAmisFileSchema(field, readonly);
25074
- break;
25075
- case 'image':
25076
- convertData = getAmisFileSchema(field, readonly);
25077
- break;
25078
- case 'file':
25079
- convertData = getAmisFileSchema(field, readonly);
24850
+ };
24851
+ break;
24852
+ case 'avatar':
24853
+ convertData = getAmisFileSchema(field, readonly);
24854
+ break;
24855
+ case 'image':
24856
+ convertData = getAmisFileSchema(field, readonly);
24857
+ break;
24858
+ case 'file':
24859
+ convertData = getAmisFileSchema(field, readonly);
24860
+ break;
24861
+ case 'formula':
24862
+ if(readonly){
24863
+ convertData = {
24864
+ type: 'static-tpl',
24865
+ tpl: getUiFieldTpl(field)
24866
+ };
24867
+ }
24868
+ break;
24869
+ case 'summary':
24870
+ if(readonly){
24871
+ convertData = {
24872
+ type: 'static-tpl',
24873
+ tpl: getUiFieldTpl(field)
24874
+ };
24875
+ }
24876
+ break;
24877
+ case 'code':
24878
+ convertData = {
24879
+ type: "editor",
24880
+ disabled: readonly ? true : false,
24881
+ language: field.language,
24882
+ editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
24883
+ };
24884
+ break;
24885
+ case 'toggle':
24886
+ convertData = {
24887
+ type: "switch",
24888
+ name: field.name,
24889
+ label: field.label,
24890
+ width: field.width,
24891
+ toggled: field.toggled,
24892
+ disabled: readonly,
24893
+ };
24894
+ break;
24895
+ case 'grid':
24896
+ if(field.subFields){
24897
+ convertData = {
24898
+ type: 'input-table',
24899
+ showIndex: true,
24900
+ columnsTogglable: false,
24901
+ strictMode:false,
24902
+ affixHeader: false, // 是否固定表头, 不固定表头, 否则form有y轴滚动条时, 表头会跟随滚动条滚动.
24903
+ needConfirm: false,
24904
+ editable: !readonly,
24905
+ addable: !readonly,
24906
+ removable: !readonly,
24907
+ draggable: !readonly,
24908
+ columns: []
24909
+ };
24910
+ // console.log(`convertData ==2====>`, field, convertData)
24911
+ for (const subField of field.subFields) {
24912
+ const subFieldName = subField.name.replace(`${field._prefix || ''}${field.name}.$.`, '').replace(`${field.name}.`, '');
24913
+ const gridSub = await convertSFieldToAmisField(Object.assign({}, subField, {name: subFieldName, isTableField: true}), readonly, ctx);
24914
+ if(gridSub){
24915
+ delete gridSub.name;
24916
+ delete gridSub.label;
24917
+ const gridItemSchema = {
24918
+ name: subFieldName,
24919
+ label: subField.label,
24920
+ quickEdit: readonly ? false : gridSub
24921
+ };
24922
+ if(["lookup", "boolean", "toggle"].indexOf(subField.type) > -1){
24923
+ gridItemSchema.type = gridSub.type;
24924
+ gridItemSchema.tpl = gridSub.tpl;
24925
+ }
24926
+ convertData.columns.push(Object.assign({}, gridItemSchema, subField.amis, {name: subFieldName}));
24927
+ }
24928
+ }
24929
+ }
25080
24930
  break;
25081
- case 'formula':
25082
- if(readonly){
24931
+ case 'object':
24932
+ if(field.subFields){
25083
24933
  convertData = {
25084
- type: 'static-tpl',
25085
- tpl: getUiFieldTpl(field)
24934
+ type: 'combo',
24935
+ items: []
25086
24936
  };
24937
+ // console.log(`convertData ======>`, field, convertData)
24938
+ for (let subField of field.subFields) {
24939
+ let subFieldName = subField.name.replace(`${field.name}.$.`, '').replace(`${field.name}.`, '');
24940
+ if(subField.type === 'grid'){
24941
+ subField = await getGridFieldSubFields(subField, ctx.__formFields);
24942
+ }else {
24943
+ if(readonly){
24944
+ subFieldName = `${field.name}.${subFieldName}`;
24945
+ }
24946
+ }
24947
+ const gridSub = await convertSFieldToAmisField(Object.assign({}, subField, {name: subFieldName}), readonly, ctx);
24948
+ if(gridSub){
24949
+ delete gridSub.name;
24950
+ delete gridSub.label;
24951
+ convertData.items.push(
24952
+ Object.assign({}, gridSub, {label: subField.label}, subField.amis, {
24953
+ name: subFieldName
24954
+ })
24955
+ );
24956
+ }
24957
+ }
24958
+ }
24959
+ break;
24960
+ }
24961
+ if(!lodash.exports.isEmpty(convertData)){
24962
+ if(field.is_wide || convertData.type === 'group'){
24963
+ convertData.className = 'col-span-2 m-1';
24964
+ }else {
24965
+ convertData.className = 'm-1';
24966
+ }
24967
+ if(readonly){
24968
+ convertData.className = `${convertData.className} border-b`;
24969
+ }
24970
+ if(readonly){
24971
+ convertData.quickEdit = false;
24972
+ }
24973
+
24974
+ let fieldTypeClassName = ' steedos-' + convertData.type + (readonly ? '-readonly' : '-edit');
24975
+ if (convertData.className) {
24976
+ convertData.className = convertData.className + fieldTypeClassName;
24977
+ } else {
24978
+ convertData.className = fieldTypeClassName;
24979
+ }
24980
+
24981
+ if(field.visible_on && !ctx.inFilterForm){
24982
+ // convertData.visibleOn = `\$${field.visible_on.substring(1, field.visible_on.length -1).replace(/formData./g, '')}`;
24983
+ if(field.visible_on.startsWith("{{")){
24984
+ convertData.visibleOn = `${field.visible_on.substring(2, field.visible_on.length -2).replace(/formData./g, 'data.')}`;
24985
+ }else {
24986
+ convertData.visibleOn = `${field.visible_on.replace(/formData./g, 'data.')}`;
24987
+ }
24988
+ }
24989
+
24990
+ if(lodash.exports.isString(baseData.required)){
24991
+ if(baseData.required.startsWith("{{")){
24992
+ baseData.requiredOn = `${baseData.required.substring(2, baseData.required.length -2).replace(/formData./g, 'data.')}`;
24993
+ delete baseData.required;
24994
+ }
24995
+ }
24996
+
24997
+ if(convertData.type === 'group'){
24998
+ convertData.body[0] = Object.assign({}, baseData, convertData.body[0], { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name});
24999
+ return convertData
25000
+ }
25001
+ // if(ctx.mode === 'edit'){
25002
+ return Object.assign({}, baseData, convertData, { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name}, field.amis, {name: baseData.name});
25003
+ // }else{
25004
+ // return Object.assign({}, baseData, convertData, { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name});
25005
+ // }
25006
+ }
25007
+
25008
+ }
25009
+
25010
+ async function getFieldSearchable(perField, permissionFields, ctx){
25011
+ if(!ctx){
25012
+ ctx = {};
25013
+ }
25014
+ let field = perField;
25015
+ if(field.type === 'grid'){
25016
+ field = await getGridFieldSubFields(perField, permissionFields);
25017
+ }else if(perField.type === 'object'){
25018
+ field = await getObjectFieldSubFields(perField, permissionFields);
25019
+ }
25020
+
25021
+ let fieldNamePrefix = '__searchable__';
25022
+ if(field.name.indexOf(".") < 0){
25023
+ let _field = lodash.exports.cloneDeep(field);
25024
+ if(lodash.exports.includes(['textarea', 'html', 'code', 'autonumber'], field.type)){
25025
+ _field.type = 'text';
25026
+ }
25027
+
25028
+ if(lodash.exports.includes(['formula', 'summary'], field.type)){
25029
+ _field.type = field.data_type;
25030
+ _field.precision = field.precision;
25031
+ _field.scale = field.scale;
25032
+ }
25033
+ else if(field.type === "select" && field.data_type && field.data_type != "text"){
25034
+ _field.type = field.data_type;
25035
+ }
25036
+
25037
+ if(_field.type === 'number' || _field.type === 'currency'){
25038
+ _field.type = 'input-array';
25039
+ _field.inline = true;
25040
+ _field.addable = false;
25041
+ _field.removable = false;
25042
+ _field.value = [null,null];
25043
+ _field.items = {
25044
+ type: "input-number"
25045
+ };
25046
+ _field.is_wide = true;
25047
+ fieldNamePrefix = `${fieldNamePrefix}between__`;
25048
+ }
25049
+
25050
+ if(_field.type ==='date'){
25051
+ _field.type = 'input-date-range';
25052
+ _field.is_wide = true;
25053
+ fieldNamePrefix = `${fieldNamePrefix}between__`;
25054
+ }
25055
+ if(_field.type === 'datetime'){
25056
+ _field.type = 'input-datetime-range';
25057
+ _field.is_wide = true;
25058
+ fieldNamePrefix = `${fieldNamePrefix}between__`;
25059
+ }
25060
+ if(_field.type === 'time'){
25061
+ _field.type = 'input-time-range';
25062
+ _field.is_wide = true;
25063
+ fieldNamePrefix = `${fieldNamePrefix}between__`;
25064
+ }
25065
+ if(_field.reference_to === 'users'){
25066
+ _field.reference_to = 'space_users';
25067
+ _field.reference_to_field = 'user';
25068
+ }
25069
+ _field.readonly = false;
25070
+ _field.disabled = false;
25071
+ _field.multiple = true;
25072
+ _field.is_wide = false;
25073
+ _field.defaultValue = undefined;
25074
+ _field.required = false;
25075
+ _field.hidden = false;
25076
+ _field.omit = false;
25077
+
25078
+ if(_field.amis){
25079
+ delete _field.amis.static;
25080
+ delete _field.amis.staticOn;
25081
+ delete _field.amis.disabled;
25082
+ delete _field.amis.disabledOn;
25083
+ delete _field.amis.required;
25084
+ delete _field.amis.requiredOn;
25085
+ delete _field.amis.visible;
25086
+ delete _field.amis.visibleOn;
25087
+ delete _field.amis.hidden;
25088
+ delete _field.amis.hiddenOn;
25089
+ delete _field.amis.autoFill;
25090
+ }
25091
+
25092
+ const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true, inFilterForm: true}));
25093
+ if(amisField){
25094
+ return Object.assign({}, amisField,{
25095
+ submitOnChange: true
25096
+ });
25097
+ }
25098
+ }
25099
+ }
25100
+
25101
+ if(typeof window != 'undefined'){
25102
+ window.getFieldSearchable = getFieldSearchable;
25103
+ }
25104
+
25105
+
25106
+ function isFieldTypeSearchable(fieldType) {
25107
+ return !lodash.exports.includes(
25108
+ [
25109
+ "grid",
25110
+ "avatar",
25111
+ "image",
25112
+ "object",
25113
+ "[object]",
25114
+ "[Object]",
25115
+ "[grid]",
25116
+ "[text]",
25117
+ "audio",
25118
+ "file",
25119
+ ],
25120
+ fieldType
25121
+ )
25122
+ }
25123
+
25124
+ if (typeof window != 'undefined') {
25125
+ window.isFieldTypeSearchable = isFieldTypeSearchable;
25126
+ }
25127
+
25128
+
25129
+ function isFieldQuickSearchable(field, nameFieldKey) {
25130
+ let fieldSearchable = field.searchable;
25131
+ if(fieldSearchable !== false && field.name === nameFieldKey){
25132
+ // 对象上名称字段的searchable默认认为是true
25133
+ fieldSearchable = true;
25134
+ }
25135
+ if (fieldSearchable && QUICK_SEARCHABLE_FIELD_TYPES.indexOf(field.type) > -1) {
25136
+ return true;
25137
+ }
25138
+ return false;
25139
+ }
25140
+
25141
+ /******************************************************************************
25142
+ Copyright (c) Microsoft Corporation.
25143
+
25144
+ Permission to use, copy, modify, and/or distribute this software for any
25145
+ purpose with or without fee is hereby granted.
25146
+
25147
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
25148
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
25149
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25150
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25151
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25152
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25153
+ PERFORMANCE OF THIS SOFTWARE.
25154
+ ***************************************************************************** */
25155
+
25156
+ var __assign = function() {
25157
+ __assign = Object.assign || function __assign(t) {
25158
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
25159
+ s = arguments[i];
25160
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
25161
+ }
25162
+ return t;
25163
+ };
25164
+ return __assign.apply(this, arguments);
25165
+ };
25166
+
25167
+ // 方便取值的时候能够把上层的取到,但是获取的时候不会全部把所有的数据获取到。
25168
+ function createObject(superProps, props, properties) {
25169
+ if (superProps && Object.isFrozen(superProps)) {
25170
+ superProps = cloneObject(superProps);
25171
+ }
25172
+ var obj = superProps
25173
+ ? Object.create(superProps, __assign(__assign({}, properties), { __super: {
25174
+ value: superProps,
25175
+ writable: false,
25176
+ enumerable: false
25177
+ } }))
25178
+ : Object.create(Object.prototype, properties);
25179
+ props &&
25180
+ isObject(props) &&
25181
+ Object.keys(props).forEach(function (key) { return (obj[key] = props[key]); });
25182
+ return obj;
25183
+ }
25184
+ function cloneObject(target, persistOwnProps) {
25185
+ if (persistOwnProps === void 0) { persistOwnProps = true; }
25186
+ var obj = target && target.__super
25187
+ ? Object.create(target.__super, {
25188
+ __super: {
25189
+ value: target.__super,
25190
+ writable: false,
25191
+ enumerable: false
25087
25192
  }
25088
- break;
25089
- case 'summary':
25090
- if(readonly){
25091
- convertData = {
25092
- type: 'static-tpl',
25093
- tpl: getUiFieldTpl(field)
25094
- };
25193
+ })
25194
+ : Object.create(Object.prototype);
25195
+ persistOwnProps &&
25196
+ target &&
25197
+ Object.keys(target).forEach(function (key) { return (obj[key] = target[key]); });
25198
+ return obj;
25199
+ }
25200
+ function isObject(obj) {
25201
+ var typename = typeof obj;
25202
+ return (obj &&
25203
+ typename !== 'string' &&
25204
+ typename !== 'number' &&
25205
+ typename !== 'boolean' &&
25206
+ typename !== 'function' &&
25207
+ !Array.isArray(obj));
25208
+ }
25209
+
25210
+ /*
25211
+ * @Author: baozhoutao@steedos.com
25212
+ * @Date: 2022-07-05 15:55:39
25213
+ * @LastEditors: liaodaxue
25214
+ * @LastEditTime: 2023-10-20 11:38:25
25215
+ * @Description:
25216
+ */
25217
+
25218
+ let UI_SCHEMA_CACHE = {};
25219
+
25220
+ let UISchemaFunction;
25221
+
25222
+ if('undefined' != typeof window){
25223
+ if(!window.UI_SCHEMA_CACHE){
25224
+ window.UI_SCHEMA_CACHE = UI_SCHEMA_CACHE;
25225
+ }
25226
+ UI_SCHEMA_CACHE = window.UI_SCHEMA_CACHE;
25227
+ }
25228
+
25229
+ const setUISchemaCache = (key, value) => {
25230
+ UI_SCHEMA_CACHE[key] = value;
25231
+ };
25232
+
25233
+ const getUISchemaCache = (key) => {
25234
+ return lodash.exports.cloneDeep(UI_SCHEMA_CACHE[key]);
25235
+ };
25236
+
25237
+ const hasUISchemaCache = (key) => {
25238
+ return lodash.exports.has(UI_SCHEMA_CACHE, key);
25239
+ };
25240
+
25241
+ function getListViewColumns(listView, formFactor) {
25242
+ let listViewColumns = [];
25243
+ if (formFactor === "SMALL") {
25244
+ listViewColumns = !lodash.exports.isEmpty(listView.mobile_columns)
25245
+ ? listView.mobile_columns
25246
+ : lodash.exports.slice(listView.columns, 0, 4);
25247
+ } else {
25248
+ listViewColumns = listView.columns;
25249
+ }
25250
+ return listViewColumns;
25251
+ }
25252
+ function getListViewSort(listView) {
25253
+ let sort = '';
25254
+ if(listView && listView.sort && listView.sort.length){
25255
+ lodash.exports.each(listView.sort,function(item,index){
25256
+ if(lodash.exports.isArray(item)){
25257
+ const field_name = item[0];
25258
+ const order = item[1] || '';
25259
+ let sortStr = field_name + ' ' + order;
25260
+ sortStr = index > 0 ? ','+sortStr : sortStr;
25261
+ sort += sortStr;
25262
+ }else {
25263
+ let sortStr = item.field_name + ' ' + item.order;
25264
+ sortStr = index > 0 ? ','+sortStr : sortStr;
25265
+ sort += sortStr;
25095
25266
  }
25096
- break;
25097
- case 'code':
25098
- convertData = {
25099
- type: "editor",
25100
- disabled: readonly ? true : false,
25101
- language: field.language,
25102
- editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
25103
- };
25104
- break;
25105
- case 'toggle':
25106
- convertData = {
25107
- type: "switch",
25108
- name: field.name,
25109
- label: field.label,
25110
- width: field.width,
25111
- toggled: field.toggled,
25112
- disabled: readonly,
25113
- };
25114
- break;
25115
- case 'grid':
25116
- if(field.subFields){
25117
- convertData = {
25118
- type: 'input-table',
25119
- showIndex: true,
25120
- columnsTogglable: false,
25121
- strictMode:false,
25122
- affixHeader: false, // 是否固定表头, 不固定表头, 否则form有y轴滚动条时, 表头会跟随滚动条滚动.
25123
- needConfirm: false,
25124
- editable: !readonly,
25125
- addable: !readonly,
25126
- removable: !readonly,
25127
- draggable: !readonly,
25128
- columns: []
25129
- };
25130
- // console.log(`convertData ==2====>`, field, convertData)
25131
- for (const subField of field.subFields) {
25132
- const subFieldName = subField.name.replace(`${field._prefix || ''}${field.name}.$.`, '').replace(`${field.name}.`, '');
25133
- const gridSub = await convertSFieldToAmisField(Object.assign({}, subField, {name: subFieldName, isTableField: true}), readonly, ctx);
25134
- if(gridSub){
25135
- delete gridSub.name;
25136
- delete gridSub.label;
25137
- const gridItemSchema = {
25138
- name: subFieldName,
25139
- label: subField.label,
25140
- quickEdit: readonly ? false : gridSub
25141
- };
25142
- if(["lookup", "boolean", "toggle"].indexOf(subField.type) > -1){
25143
- gridItemSchema.type = gridSub.type;
25144
- gridItemSchema.tpl = gridSub.tpl;
25145
- }
25146
- convertData.columns.push(Object.assign({}, gridItemSchema, subField.amis, {name: subFieldName}));
25147
- }
25267
+ });
25268
+ }
25269
+ return sort;
25270
+ }
25271
+ function getListViewFilter(listView){
25272
+ if(!listView){
25273
+ return ;
25274
+ }
25275
+ try {
25276
+ const userId = getUserId();
25277
+ let filters = listView.filters;
25278
+ if(listView.filter_scope === 'mine'){
25279
+ if(___default.isEmpty(filters)){
25280
+ filters = [["owner", "=", userId]];
25281
+ }else {
25282
+ if(___default.isString(filters) && ___default.startsWith(___default.trim(filters), "function")){
25283
+ filters = new Function(`return ${filters}`);
25284
+ filters = filters();
25148
25285
  }
25149
- }
25150
- break;
25151
- case 'object':
25152
- if(field.subFields){
25153
- convertData = {
25154
- type: 'combo',
25155
- items: []
25156
- };
25157
- // console.log(`convertData ======>`, field, convertData)
25158
- for (let subField of field.subFields) {
25159
- let subFieldName = subField.name.replace(`${field.name}.$.`, '').replace(`${field.name}.`, '');
25160
- if(subField.type === 'grid'){
25161
- subField = await getGridFieldSubFields(subField, ctx.__formFields);
25162
- }else {
25163
- if(readonly){
25164
- subFieldName = `${field.name}.${subFieldName}`;
25165
- }
25166
- }
25167
- const gridSub = await convertSFieldToAmisField(Object.assign({}, subField, {name: subFieldName}), readonly, ctx);
25168
- if(gridSub){
25169
- delete gridSub.name;
25170
- delete gridSub.label;
25171
- convertData.items.push(
25172
- Object.assign({}, gridSub, {label: subField.label}, subField.amis, {
25173
- name: subFieldName
25174
- })
25175
- );
25176
- }
25286
+ if(___default.isArray(filters)){
25287
+ filters.push(["owner", "=", userId]);
25288
+ }else {
25289
+ console.debug(`listView filters is not array`, listView);
25290
+ throw new Error('filters is not array')
25177
25291
  }
25178
25292
  }
25179
- break;
25293
+ };
25294
+ return filters;
25295
+ } catch (error) {
25296
+ console.error(error);
25297
+ }
25298
+ }
25299
+
25300
+ function formatUISchemaCache(objectName, uiSchema){
25301
+ setUISchemaCache(objectName, uiSchema);
25302
+ lodash.exports.each(uiSchema.fields, (field)=>{
25303
+ try {
25304
+ if(field.type === "lookup" && field._reference_to && ___default.isString(field._reference_to)){
25305
+ field.reference_to = eval(`(${field._reference_to})`)();
25306
+ }
25307
+ } catch (exception) {
25308
+ field.reference_to = undefined;
25309
+ console.error(exception);
25310
+ }
25311
+ });
25312
+ lodash.exports.each(uiSchema.list_views, (v, k)=>{
25313
+ v.name = k;
25314
+ if(!lodash.exports.has(v, 'columns')){
25315
+ v.columns = uiSchema.list_views.all.columns;
25316
+ }
25317
+ });
25318
+ }
25319
+
25320
+ async function getUISchema(objectName, force) {
25321
+ if (!objectName) {
25322
+ return;
25323
+ }
25324
+ if (hasUISchemaCache(objectName) && !force) {
25325
+ return getUISchemaCache(objectName);
25326
+ }
25327
+ let uiSchema = null;
25328
+ try {
25329
+ if(UISchemaFunction);
25330
+ else {
25331
+ const url = `/service/api/@${objectName.replace(/\./g, "_")}/uiSchema`;
25332
+ uiSchema = await fetchAPI(url, { method: "get" });
25333
+ }
25334
+ if(!uiSchema){
25335
+ return ;
25336
+ }
25337
+ formatUISchemaCache(objectName, uiSchema);
25338
+ } catch (error) {
25339
+ console.error(`getUISchema`, objectName, error);
25340
+ setUISchemaCache(objectName, null);
25341
+ }
25342
+ return getUISchemaCache(objectName);
25343
+ }
25344
+
25345
+ function getUISchemaSync(objectName, force) {
25346
+ if (!objectName) {
25347
+ return;
25180
25348
  }
25181
- if(!lodash.exports.isEmpty(convertData)){
25182
- if(field.is_wide || convertData.type === 'group'){
25183
- convertData.className = 'col-span-2 m-1';
25184
- }else {
25185
- convertData.className = 'm-1';
25186
- }
25187
- if(readonly){
25188
- convertData.className = `${convertData.className} border-b`;
25349
+ if (hasUISchemaCache(objectName) && !force) {
25350
+ return getUISchemaCache(objectName);
25351
+ }
25352
+ let uiSchema = null;
25353
+ try {
25354
+
25355
+ const url = `/service/api/@${objectName.replace(/\./g, "_")}/uiSchema`;
25356
+ uiSchema = Steedos.authRequest(url, {
25357
+ type: 'GET',
25358
+ async: false,
25359
+ });
25360
+
25361
+ if(!uiSchema){
25362
+ return ;
25189
25363
  }
25190
- if(readonly){
25191
- convertData.quickEdit = false;
25364
+ formatUISchemaCache(objectName, uiSchema);
25365
+ } catch (error) {
25366
+ console.error(`getUISchema`, objectName, error);
25367
+ setUISchemaCache(objectName, null);
25368
+ }
25369
+ return getUISchemaCache(objectName);
25370
+ }
25371
+
25372
+ // 获取列表视图
25373
+ async function getListSchema(
25374
+ appName,
25375
+ objectName,
25376
+ listViewName,
25377
+ ctx = {}
25378
+ ) {
25379
+ const uiSchema = await getUISchema(objectName);
25380
+ if(!uiSchema){
25381
+ return {}
25382
+ }
25383
+ const listView = lodash.exports.find(
25384
+ uiSchema.list_views,
25385
+ (listView, name) => {
25386
+ // 传入listViewName空值则取第一个
25387
+ if(!listViewName){
25388
+ listViewName = name;
25389
+ }
25390
+ return name === listViewName || listView._id === listViewName;
25192
25391
  }
25392
+ );
25193
25393
 
25194
- let fieldTypeClassName = ' steedos-' + convertData.type + (readonly ? '-readonly' : '-edit');
25195
- if (convertData.className) {
25196
- convertData.className = convertData.className + fieldTypeClassName;
25197
- } else {
25198
- convertData.className = fieldTypeClassName;
25394
+ if (!listView) {
25395
+ return { uiSchema };
25396
+ }
25397
+
25398
+ // 直接返回自定义的列表视图schema
25399
+ if(listView.enable_amis_schema && listView.amis_schema){
25400
+ const amisSchema = lodash.exports.isString(listView.amis_schema) ? JSON.parse(listView.amis_schema) : listView.amis_schema;
25401
+ return {
25402
+ uiSchema,
25403
+ isCustomAmisSchema: true,
25404
+ amisSchema
25405
+ };
25406
+ }
25407
+
25408
+ let listViewColumns = getListViewColumns(listView, ctx.formFactor);
25409
+ let sort = getListViewSort(listView);
25410
+ let listviewFilter = getListViewFilter(listView);
25411
+ let listview_filters = listView && listView._filters;
25412
+ // 返回 calendar 组件
25413
+ if(listView.type === "calendar"){
25414
+ const amisSchema = {
25415
+ "type": "steedos-object-calendar",
25416
+ "objectApiName": objectName,
25417
+ "filters": listviewFilter,
25418
+ "filtersFunction": listview_filters,
25419
+ "sort": sort,
25420
+ ...listView.options
25421
+ };
25422
+ return {
25423
+ uiSchema,
25424
+ isCalendar: true,
25425
+ amisSchema
25426
+ };
25427
+ }
25428
+
25429
+ const defaults = ctx.defaults || {};
25430
+
25431
+ // // 未自定义header 且显示header的时候, 使用系统header
25432
+ // if(!defaults.headerSchema && ctx.showHeader){
25433
+ // defaults.headerSchema = getObjectListHeader(uiSchema, listViewName);
25434
+ // }
25435
+
25436
+ // // 如果不显示header,则清理掉
25437
+ // if(!ctx.showHeader){
25438
+ // defaults.headerSchema = null;
25439
+ // }
25440
+
25441
+ defaults.headerSchema = null;
25442
+
25443
+ /**
25444
+ * 本次存储代码段
25445
+ */
25446
+ try {
25447
+ const listViewPropsStoreKey = location.pathname + "/crud";
25448
+ let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
25449
+ /**
25450
+ * localListViewProps规范来自crud请求api中api.data.$self参数值的。
25451
+ * 比如:{"perPage":20,"page":1,"__searchable__name":"7","__searchable__between__n1__c":[null,null],"filter":[["name","contains","a"]]}
25452
+ * __searchable__...:顶部放大镜搜索条件
25453
+ * filter:右侧过滤器
25454
+ * perPage:每页条数
25455
+ * page:当前页码
25456
+ * orderBy:排序字段
25457
+ * orderDir:排序方向
25458
+ */
25459
+ if (localListViewProps) {
25460
+ localListViewProps = JSON.parse(localListViewProps);
25461
+ // localListViewProps.perPage = 3;
25462
+ let listSchema = {};
25463
+ if(localListViewProps.orderBy){
25464
+ listSchema.orderBy = localListViewProps.orderBy;
25465
+ }
25466
+ if(localListViewProps.orderDir){
25467
+ listSchema.orderDir = localListViewProps.orderDir;
25199
25468
  }
25200
25469
 
25201
- if(field.visible_on && !ctx.inFilterForm){
25202
- // convertData.visibleOn = `\$${field.visible_on.substring(1, field.visible_on.length -1).replace(/formData./g, '')}`;
25203
- if(field.visible_on.startsWith("{{")){
25204
- convertData.visibleOn = `${field.visible_on.substring(2, field.visible_on.length -2).replace(/formData./g, 'data.')}`;
25205
- }else {
25206
- convertData.visibleOn = `${field.visible_on.replace(/formData./g, 'data.')}`;
25207
- }
25470
+ if(localListViewProps.perPage){
25471
+ listSchema.defaultParams = {
25472
+ perPage: localListViewProps.perPage
25473
+ };
25208
25474
  }
25475
+ defaults.listSchema = lodash.exports.defaultsDeep({}, listSchema, defaults.listSchema || {});
25476
+ }
25477
+ }
25478
+ catch (ex) {
25479
+ console.error("本地存储中crud参数解析异常:", ex);
25480
+ }
25209
25481
 
25210
- if(lodash.exports.isString(baseData.required)){
25211
- if(baseData.required.startsWith("{{")){
25212
- baseData.requiredOn = `${baseData.required.substring(2, baseData.required.length -2).replace(/formData./g, 'data.')}`;
25213
- delete baseData.required;
25214
- }
25482
+ ctx.defaults = defaults;
25483
+
25484
+ if (listViewName == "recent") {
25485
+ listview_filters = `
25486
+ function(filters, data) {
25487
+ var result = Steedos.authRequest('/graphql', {
25488
+ type: 'POST',
25489
+ async: false,
25490
+ data: JSON.stringify({
25491
+ query: '{object_recent_viewed(filters: [["record.o","=","' + data.objectName + '"],["space","=","' + data.context.tenantId + '"],["owner","=","' + data.context.userId + '"]],sort:"modified desc",top:50){ _id,record} }'
25492
+ }),
25493
+ });
25494
+ var _ids = []
25495
+ result.data.object_recent_viewed.forEach(function (item) {
25496
+ _ids = _ids.concat(item.record.ids)
25497
+ })
25498
+ return ["_id", "=", _ids];
25215
25499
  }
25500
+ `;
25501
+ }
25502
+ const amisSchema = {
25503
+ "type": "steedos-object-table",
25504
+ "objectApiName": objectName,
25505
+ "columns": listViewColumns,
25506
+ "extraColumns": listView.extra_columns,
25507
+ "filters": listviewFilter,
25508
+ "filtersFunction": listview_filters,
25509
+ "sort": sort,
25510
+ "ctx": ctx,
25511
+ "requestAdaptor": listView.requestAdaptor || ctx.requestAdaptor,
25512
+ "adaptor": listView.adaptor || ctx.adaptor,
25513
+ "headerToolbarItems": ctx.headerToolbarItems,
25514
+ "filterVisible": ctx.filterVisible,
25515
+ "rowClassNameExpr": ctx.rowClassNameExpr,
25516
+ "crudDataFilter": ctx.crudDataFilter,
25517
+ "onCrudDataFilter": ctx.onCrudDataFilter
25518
+ };
25519
+ // console.log(`getListSchema===>`,amisSchema)
25520
+ return {
25521
+ uiSchema,
25522
+ amisSchema,
25523
+ };
25524
+ }
25216
25525
 
25217
- if(convertData.type === 'group'){
25218
- convertData.body[0] = Object.assign({}, baseData, convertData.body[0], { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name});
25219
- return convertData
25526
+
25527
+ if(typeof window != 'undefined'){
25528
+ window.getUISchema = getUISchema;
25529
+ window.getUISchemaSync = getUISchemaSync;
25530
+ window.getListSchema = getListSchema;
25531
+ }
25532
+
25533
+ function getNumberTpl(field){
25534
+ return `<span>\${_display.${field.name}}</span>`
25535
+ }
25536
+
25537
+ function getTimeTpl(field){
25538
+ return `<span>\${_display.${field.name}}</span>`
25539
+ }
25540
+
25541
+ function getDateTpl(field){
25542
+ return `<span>\${_display.${field.name}}</span>`
25543
+ }
25544
+
25545
+
25546
+ function getDateTimeTpl(field){
25547
+ return `<span>\${_display.${field.name}}</span>`
25548
+ }
25549
+
25550
+ function getUiFieldTpl(field){
25551
+ return `<span>\${_display.${field.name}}</span>`
25552
+ }
25553
+
25554
+ function getUiFileSizeTpl(field){
25555
+ return `<span>\${_display.${field.name}}</span>`
25556
+ }
25557
+
25558
+ //TODO 处理name字段
25559
+ async function getRefObjectNameFieldName(field){
25560
+ const refUiSchema = await getUISchema(field.reference_to);
25561
+ const NAME_FIELD_KEY = refUiSchema.NAME_FIELD_KEY || 'name';
25562
+ return NAME_FIELD_KEY;
25563
+ }
25564
+
25565
+ function getSelectTpl(field){
25566
+ return `<span>\${_display.${field.name}}</span>`
25567
+ }
25568
+ function getSelectMap(selectOptions){
25569
+ let map = {};
25570
+ lodash.exports.forEach(selectOptions,(option)=>{
25571
+ const optionValue = option.value + '';
25572
+ const optionColor = option.color + '';
25573
+ if(optionColor){
25574
+ const background = optionColor.charAt(0) === '#' ? optionColor : '#'+optionColor;
25575
+ const color = getContrastColor(background);
25576
+ const optionColorStyle = 'background:'+background+';color:'+color+';line-height:1.5rem';
25577
+ map[optionValue] = `<span class="rounded-xl px-2 py-1" style='${optionColorStyle}'>${option.label}</span>`;
25578
+ }else {
25579
+ map[optionValue] = option.label;
25220
25580
  }
25221
- // if(ctx.mode === 'edit'){
25222
- return Object.assign({}, baseData, convertData, { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name}, field.amis, {name: baseData.name});
25223
- // }else{
25224
- // return Object.assign({}, baseData, convertData, { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name});
25225
- // }
25226
- }
25227
-
25581
+ });
25582
+ return map;
25228
25583
  }
25229
25584
 
25230
- async function getFieldSearchable(perField, permissionFields, ctx){
25231
- if(!ctx){
25232
- ctx = {};
25585
+ function getNameTplUrl(field, ctx){
25586
+ if(ctx.objectName === 'cms_files'){
25587
+ return `\${context.rootUrl}/api/files/files/\${versions[0]}?download=true`
25233
25588
  }
25234
- let field = perField;
25235
- if(field.type === 'grid'){
25236
- field = await getGridFieldSubFields(perField, permissionFields);
25237
- }else if(perField.type === 'object'){
25238
- field = await getObjectFieldSubFields(perField, permissionFields);
25589
+ const href = Router.getObjectDetailPath({
25590
+ ...ctx, formFactor: ctx.formFactor, appId: "${appId}", objectName: ctx.objectName || "${objectName}", recordId: `\${${ctx.idFieldName}}`
25591
+ });
25592
+ return href;
25593
+ }
25594
+
25595
+ function getNameTpl(field, ctx){
25596
+ const href = getNameTplUrl(field, ctx);
25597
+ let linkTarget = "";
25598
+ if(ctx && ctx.isLookup){
25599
+ linkTarget = "target='_blank'";
25239
25600
  }
25601
+ return `<a href="${href}" ${linkTarget}>\${${field.name}}</a>`
25602
+ }
25240
25603
 
25241
- let fieldNamePrefix = '__searchable__';
25242
- if(field.name.indexOf(".") < 0){
25243
- let _field = lodash.exports.cloneDeep(field);
25244
- if(lodash.exports.includes(['textarea', 'html', 'code', 'autonumber'], field.type)){
25245
- _field.type = 'text';
25604
+ function getRelatedFieldTpl(field, ctx){
25605
+ let tpl = '';
25606
+ if(!field.reference_to && (field.optionsFunction || field._optionsFunction || field.options)){
25607
+ if(field.isTableField){
25608
+ return `\${${field.name}}`
25609
+ }else {
25610
+ return `\${${field.name}__label}`
25246
25611
  }
25612
+ }
25247
25613
 
25248
- if(lodash.exports.includes(['formula', 'summary'], field.type)){
25249
- _field.type = field.data_type;
25250
- _field.precision = field.precision;
25251
- _field.scale = field.scale;
25252
- }
25253
- else if(field.type === "select" && field.data_type && field.data_type != "text"){
25254
- _field.type = field.data_type;
25255
- }
25614
+ let linkTarget = "";
25615
+ if(ctx && ctx.isLookup){
25616
+ linkTarget = "target='_blank'";
25617
+ }
25256
25618
 
25257
- if(_field.type === 'number' || _field.type === 'currency'){
25258
- _field.type = 'input-array';
25259
- _field.inline = true;
25260
- _field.addable = false;
25261
- _field.removable = false;
25262
- _field.value = [null,null];
25263
- _field.items = {
25264
- type: "input-number"
25265
- };
25266
- _field.is_wide = true;
25267
- fieldNamePrefix = `${fieldNamePrefix}between__`;
25268
- }
25619
+ const onlyDisplayLookLabel = ctx.onlyDisplayLookLabel;
25269
25620
 
25270
- if(_field.type ==='date'){
25271
- _field.type = 'input-date-range';
25272
- _field.is_wide = true;
25273
- fieldNamePrefix = `${fieldNamePrefix}between__`;
25274
- }
25275
- if(_field.type === 'datetime'){
25276
- _field.type = 'input-datetime-range';
25277
- _field.is_wide = true;
25278
- fieldNamePrefix = `${fieldNamePrefix}between__`;
25279
- }
25280
- if(_field.type === 'time'){
25281
- _field.type = 'input-time-range';
25282
- _field.is_wide = true;
25283
- fieldNamePrefix = `${fieldNamePrefix}between__`;
25284
- }
25285
- if(_field.reference_to === 'users'){
25286
- _field.reference_to = 'space_users';
25287
- _field.reference_to_field = 'user';
25288
- }
25289
- _field.readonly = false;
25290
- _field.disabled = false;
25291
- _field.multiple = true;
25292
- _field.is_wide = false;
25293
- _field.defaultValue = undefined;
25294
- _field.required = false;
25295
- _field.hidden = false;
25296
- _field.omit = false;
25621
+ let fieldDataStrTpl = `data._display.${field.name}`;
25297
25622
 
25298
- if(_field.amis){
25299
- delete _field.amis.static;
25300
- delete _field.amis.staticOn;
25301
- delete _field.amis.disabled;
25302
- delete _field.amis.disabledOn;
25303
- delete _field.amis.required;
25304
- delete _field.amis.requiredOn;
25305
- delete _field.amis.visible;
25306
- delete _field.amis.visibleOn;
25307
- delete _field.amis.hidden;
25308
- delete _field.amis.hiddenOn;
25309
- delete _field.amis.autoFill;
25623
+ if(field.isTableField){
25624
+ fieldDataStrTpl = `data.${field.name}`;
25625
+ }
25626
+
25627
+ if(_.isString(field.reference_to) || !field.reference_to){
25628
+ if(field.multiple){
25629
+ let labelTpl = `<%=item.label%>`;
25630
+ if(!onlyDisplayLookLabel){
25631
+ const href = Router.getObjectDetailPath({
25632
+ formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
25633
+ });
25634
+ labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
25635
+ }
25636
+ tpl = `
25637
+ <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item,index) { %> <% if(index>0 && index<${fieldDataStrTpl}.length){ %> , <% } %> ${labelTpl} <% }); %><% } %>
25638
+ `;
25639
+ }else {
25640
+ let labelTpl = `\${_display.${field.name}.label}`;
25641
+ let objectNameTpl = `\${_display.${field.name}.objectName}`;
25642
+ let recordIdTpl = `\${_display.${field.name}.value}`;
25643
+ if(field.isTableField){
25644
+ labelTpl = `\${${field.name}.label}`;
25645
+ objectNameTpl = `\${${field.name}.objectName}`;
25646
+ recordIdTpl = `\${${field.name}.value}`;
25647
+ }
25648
+ if(!onlyDisplayLookLabel){
25649
+ const href = Router.getObjectDetailPath({
25650
+ formFactor: ctx.formFactor, appId: "${appId}", objectName: `${objectNameTpl}`, recordId: `${recordIdTpl}`
25651
+ });
25652
+ labelTpl = `<a href="${href}" ${linkTarget}>${labelTpl}</a>`;
25653
+ }
25654
+ tpl = labelTpl;
25310
25655
  }
25311
25656
 
25312
- const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true, inFilterForm: true}));
25313
- if(amisField){
25314
- return Object.assign({}, amisField,{
25315
- submitOnChange: true
25657
+
25658
+ }else {
25659
+ let labelTpl = `<%=item.label%>`;
25660
+ if(!onlyDisplayLookLabel){
25661
+ const href = Router.getObjectDetailPath({
25662
+ formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
25316
25663
  });
25664
+ labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
25317
25665
  }
25666
+ tpl = `
25667
+ <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item) { %> ${labelTpl} <% }); %><% } %>
25668
+ `;
25318
25669
  }
25670
+ return tpl
25319
25671
  }
25320
25672
 
25321
- if(typeof window != 'undefined'){
25322
- window.getFieldSearchable = getFieldSearchable;
25673
+ async function getLookupTpl(field, ctx){
25674
+ if(!field.reference_to){
25675
+ return getSelectTpl(field)
25676
+ }
25677
+ const NAME_FIELD_KEY = await getRefObjectNameFieldName(field);
25678
+ if(field.multiple){
25679
+ const href = Router.getObjectDetailPath({
25680
+ formFactor: ctx.formFactor, appId: ctx.appId, objectName: field.reference_to, recordId: `<%=item._id%>`, _templateType: "JavaScript"
25681
+ });
25682
+ return `
25683
+ <% if (data.${field.name} && data.${field.name}.length) { %><% data.${field.name}.forEach(function(item) { %> <a href="${href}"><%=item.${NAME_FIELD_KEY}%></a> <% }); %><% } %>
25684
+ `
25685
+ }else {
25686
+ const href = Router.getObjectDetailPath({
25687
+ formFactor: ctx.formFactor, appId: ctx.appId, objectName: field.reference_to, recordId: `\${${field.name}._id}`
25688
+ });
25689
+ return `<a href="${href}">\${${field.name}.${NAME_FIELD_KEY}}</a>`
25690
+ }
25691
+
25323
25692
  }
25324
25693
 
25325
-
25326
- function isFieldTypeSearchable(fieldType) {
25327
- return !lodash.exports.includes(
25328
- [
25329
- "grid",
25330
- "avatar",
25331
- "image",
25332
- "object",
25333
- "[object]",
25334
- "[Object]",
25335
- "[grid]",
25336
- "[text]",
25337
- "audio",
25338
- "file",
25339
- ],
25340
- fieldType
25341
- )
25694
+ function getSwitchTpl(field){
25695
+ let fieldDataStrTpl = `data._display.${field.name}`;
25696
+ if(field.isTableField){
25697
+ fieldDataStrTpl = `data.${field.name}`;
25698
+ }
25699
+ return `<% if (data.${field.name}) { %>
25700
+ <span class="slds-icon_container slds-icon-utility-check slds-current-color" title="<%=${fieldDataStrTpl}%>">
25701
+ <span ><%= ${fieldDataStrTpl} === "" ? "<svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' class='w-4 h-4'><path stroke-linecap='round' stroke-linejoin='round' d='M4.5 12.75l6 6 9-13.5' /></svg>" : ${fieldDataStrTpl} %></span>
25702
+ </span>
25703
+ <% } %>`
25342
25704
  }
25343
25705
 
25344
- if (typeof window != 'undefined') {
25345
- window.isFieldTypeSearchable = isFieldTypeSearchable;
25706
+ function getPasswordTpl(field){
25707
+ return `<% if (data.${field.name}) { %>
25708
+ <span>······</span>
25709
+ <% } %>`
25346
25710
  }
25347
25711
 
25712
+ function getLocationTpl(field){
25713
+ return `\${${field.name} ? ${field.name}.address : ''}`
25714
+ }
25348
25715
 
25349
- function isFieldQuickSearchable(field, nameFieldKey) {
25350
- let fieldSearchable = field.searchable;
25351
- if(fieldSearchable !== false && field.name === nameFieldKey){
25352
- // 对象上名称字段的searchable默认认为是true
25353
- fieldSearchable = true;
25716
+ async function getFieldTpl (field, options){
25717
+ if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLookLabel){
25718
+ return getNameTpl(field, options)
25354
25719
  }
25355
- if (fieldSearchable && QUICK_SEARCHABLE_FIELD_TYPES.indexOf(field.type) > -1) {
25356
- return true;
25720
+ switch (field.type) {
25721
+ case 'password':
25722
+ return getPasswordTpl(field);
25723
+ case 'boolean':
25724
+ return getSwitchTpl(field);
25725
+ case 'toggle':
25726
+ return getSwitchTpl(field);
25727
+ case 'select':
25728
+ return getSelectTpl(field);
25729
+ case 'time':
25730
+ return getTimeTpl(field);
25731
+ case 'date':
25732
+ return getDateTpl(field);
25733
+ case 'datetime':
25734
+ return getDateTimeTpl(field);
25735
+ case 'lookup':
25736
+ return await getRelatedFieldTpl(field, options);
25737
+ case 'master_detail':
25738
+ return await getRelatedFieldTpl(field, options);
25739
+ case 'location':
25740
+ return await getLocationTpl(field);
25741
+ case 'number':
25742
+ case 'currency':
25743
+ return await getNumberTpl(field);
25744
+ case 'percent':
25745
+ case 'formula':
25746
+ case 'summary':
25747
+ return getUiFieldTpl(field)
25748
+ case 'filesize':
25749
+ return getUiFileSizeTpl(field)
25357
25750
  }
25358
- return false;
25359
25751
  }
25360
25752
 
25361
25753
  /*
@@ -25808,7 +26200,7 @@ crudService && crudService.setData({showFieldsFilter: toShowFieldsFilter});
25808
26200
 
25809
26201
  async function getTableColumns(fields, options){
25810
26202
  const columns = [];
25811
- if(!options.isLookup){
26203
+ if(!options.isLookup && !options.isInputTable){
25812
26204
  //将_display放入crud的columns中,可以通过setvalue修改行内数据域的_display,而不影响上层items的_display,用于批量编辑
25813
26205
  columns.push({name: '_display',type: 'static', width: 32, placeholder: "",id: "_display_${_index}", className: "hidden"});
25814
26206
  columns.push({name: '_index',type: 'text', width: 32, placeholder: ""});
@@ -25951,7 +26343,7 @@ crudService && crudService.setData({showFieldsFilter: toShowFieldsFilter});
25951
26343
  }
25952
26344
  }
25953
26345
  // columns.push(getOperation(fields));
25954
- if(!options.isLookup && !lodash.exports.some(columns, { name: options.labelFieldName })){
26346
+ if(!options.isLookup && !options.isInputTable && !lodash.exports.some(columns, { name: options.labelFieldName })){
25955
26347
  // 没有名称字段时显示序号字段为链接,lookup弹出的picker不需要此功能
25956
26348
  const href = Router.getObjectDetailPath({
25957
26349
  ...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
@@ -26135,624 +26527,232 @@ crudService && crudService.setData({showFieldsFilter: toShowFieldsFilter});
26135
26527
  "api": {
26136
26528
  "url": url,
26137
26529
  "method": "get",
26138
- "headers": {
26139
- "Authorization": "Bearer ${context.tenantId},${context.authToken}"
26140
- }
26141
- }
26142
- },
26143
- "actionType": "download"
26144
- }
26145
- ],
26146
- "weight": 0
26147
- }
26148
- }
26149
- };
26150
- }
26151
-
26152
- }
26153
-
26154
- columns.push(column);
26155
-
26156
-
26157
- return columns;
26158
- }
26159
-
26160
- function getDefaultParams(options){
26161
- return {
26162
- perPage: options.top || options.perPage || config.listView.perPage
26163
- }
26164
- }
26165
-
26166
- function getButtonVisibleOn(button){
26167
- let visible= button.visible;
26168
-
26169
- if(button._visible){
26170
- visible = button._visible;
26171
- }
26172
-
26173
- if(lodash.exports.isBoolean(visible)){
26174
- visible = visible.toString();
26175
- }
26176
-
26177
- if(visible){
26178
- // if(visible.indexOf("Meteor.") > 0 || visible.indexOf("Creator.") > 0 || visible.indexOf("Session.") > 0){
26179
- // console.warn('无效的visible', visible)
26180
- // return 'false';
26181
- // }
26182
- if(visible.trim().startsWith('function')){
26183
- return `${visible}(objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
26184
- }
26185
- return visible;
26186
- }
26187
-
26188
- if(button.type === 'amis_button'){
26189
- const amisSchema = button.amis_schema;
26190
- if(amisSchema && amisSchema.body && amisSchema.body.length > 0){
26191
- const btn1 = amisSchema.body[0];
26192
- return btn1.visibleOn
26193
- }
26194
- }
26195
- }
26196
-
26197
- async function getTableOperation(ctx){
26198
- const buttons = ctx.buttons;
26199
- const operationButtons = [];
26200
- lodash.exports.each(buttons, (button)=>{
26201
- if(lodash.exports.isBoolean(button.visible)){
26202
- button.visible = button.visible.toString();
26203
- }
26204
- // operationButtons.push({
26205
- // type: 'button',
26206
- // label: button.label,
26207
- // visibleOn: button.visible ? `${button.visible}` : (button._visible ? `${button._visible}` : null),
26208
- // onEvent: {
26209
- // click: {
26210
- // actions: []
26211
- // }
26212
- // }
26213
- // })
26214
-
26215
- operationButtons.push({
26216
- type: 'steedos-object-button',
26217
- name: button.name,
26218
- objectName: button.objectName,
26219
- visibleOn: getButtonVisibleOn(button),
26220
- className: 'antd-Button--default'
26221
- });
26222
- });
26223
- if(operationButtons.length < 1){
26224
- return ;
26225
- }
26226
- return {
26227
- type: 'operation',
26228
- label: "",
26229
- fixed: 'right',
26230
- labelClassName: 'text-center',
26231
- className: 'text-center steedos-listview-operation w-10',
26232
- buttons: [
26233
- {
26234
- "type": "steedos-dropdown-button",
26235
- "label": "xxx",
26236
- "buttons": operationButtons,
26237
- "placement": "bottomRight",
26238
- "overlayClassName": "shadow !min-w-[160px]",
26239
- "trigger": ["click"],
26240
- "id": "u:c2140a365019",
26241
- onOpenApi: {
26242
- url: `\${context.rootUrl}/service/api/@\${objectName}/recordPermissions/\${_id}`,
26243
- method: "get",
26244
- requestAdaptor: "api.data={}; return api;",
26245
- headers: {
26246
- Authorization: "Bearer ${context.tenantId},${context.authToken}"
26247
- },
26248
- adaptor: `
26249
- payload = {
26250
- record: {
26251
- recordPermissions: payload
26252
- }
26253
- };
26254
- return payload;
26255
- `,
26256
- }
26257
- }
26258
- ]
26259
- }
26260
- }
26261
-
26262
- async function getDefaultCrudCard(columns, options) {
26263
- let labelFieldName = options?.labelFieldName || "name";
26264
- let titleColumn, bodyColumns = [];
26265
- columns.forEach(function (item) {
26266
- delete item.quickEdit;
26267
- delete item.width;
26268
- if (item.name === labelFieldName) {
26269
- titleColumn = item;
26270
- }
26271
- else {
26272
- if (item.name !== "_index") {
26273
- bodyColumns.push(item);
26274
- }
26275
- }
26276
- });
26277
- let card = {
26278
- "header": {
26279
- "title": titleColumn.tpl
26280
- },
26281
- body: bodyColumns,
26282
- // useCardLabel: false,
26283
- toolbar: []
26284
- };
26285
- let hideToolbarOperation = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
26286
- if(!hideToolbarOperation){
26287
- let toolbarOperation = await getTableOperation(options);
26288
- if (toolbarOperation) {
26289
- toolbarOperation.className += " inline-block w-auto";
26290
- }
26291
- card.toolbar.push(toolbarOperation);
26292
- }
26293
- return card;
26294
- }
26295
-
26296
- async function getTableSchema$1(fields, options){
26297
- if(!options){
26298
- options = {};
26299
- }
26300
- let { isLookup, hiddenColumnOperation } = options;
26301
- const defaults = options.defaults;
26302
- const listSchema = (defaults && defaults.listSchema) || {};
26303
-
26304
- let columns = [];
26305
- let useMobileColumns = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
26306
- if(isLookup){
26307
- // 在lookup手机端列表模式调式好之前不使用getMobileTableColumns
26308
- useMobileColumns = false;
26309
- }
26310
- if(listSchema.mode && listSchema.mode !== "table"){
26311
- // 如果指定的mode,则不走我们内置的手机端列表效果,使用steedos组件内部开发的默认card/list效果,或者由用户自己实现card/list模式的crud列表
26312
- useMobileColumns = false;
26313
- }
26314
- if(useMobileColumns){
26315
- columns = await getMobileTableColumns(fields, options);
26316
- }
26317
- else {
26318
- columns = await getTableColumns(fields, options);
26319
-
26320
- if(listSchema.mode === "cards"){
26321
- let card = listSchema.card;
26322
- if(!card){
26323
- card = await getDefaultCrudCard(columns, options);
26324
- }
26325
- return {
26326
- mode: "cards",
26327
- perPageAvailable: [5, 10, 20, 50, 100, 500],
26328
- name: "thelist",
26329
- headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
26330
- className: "",
26331
- draggable: false,
26332
- defaultParams: getDefaultParams(options),
26333
- card: card,
26334
- syncLocation: false,
26335
- keepItemSelectionOnPageChange: true,
26336
- checkOnItemClick: isLookup ? true : false,
26337
- labelTpl: `\${${options.labelFieldName}}`,
26338
- autoFillHeight: false, // 自动高度效果不理想,先关闭
26339
- columnsTogglable: false
26340
- }
26341
- }
26342
-
26343
- if(!isLookup && !hiddenColumnOperation){
26344
- columns.push(await getTableOperation(options));
26345
- }
26346
- }
26347
-
26348
- return {
26349
- mode: "table",
26350
- perPageAvailable: [5, 10, 20, 50, 100, 500],
26351
- name: "thelist",
26352
- headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
26353
- className: "",
26354
- draggable: false,
26355
- defaultParams: getDefaultParams(options),
26356
- columns: columns,
26357
- syncLocation: false,
26358
- keepItemSelectionOnPageChange: true,
26359
- checkOnItemClick: isLookup ? true : false,
26360
- labelTpl: `\${${options.labelFieldName}}`,
26361
- autoFillHeight: false, // 自动高度效果不理想,先关闭
26362
- columnsTogglable: false,
26363
- }
26364
- }
26365
-
26366
- /******************************************************************************
26367
- Copyright (c) Microsoft Corporation.
26368
-
26369
- Permission to use, copy, modify, and/or distribute this software for any
26370
- purpose with or without fee is hereby granted.
26371
-
26372
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
26373
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
26374
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
26375
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26376
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26377
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26378
- PERFORMANCE OF THIS SOFTWARE.
26379
- ***************************************************************************** */
26380
-
26381
- var __assign = function() {
26382
- __assign = Object.assign || function __assign(t) {
26383
- for (var s, i = 1, n = arguments.length; i < n; i++) {
26384
- s = arguments[i];
26385
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
26386
- }
26387
- return t;
26388
- };
26389
- return __assign.apply(this, arguments);
26390
- };
26391
-
26392
- // 方便取值的时候能够把上层的取到,但是获取的时候不会全部把所有的数据获取到。
26393
- function createObject(superProps, props, properties) {
26394
- if (superProps && Object.isFrozen(superProps)) {
26395
- superProps = cloneObject(superProps);
26530
+ "headers": {
26531
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
26532
+ }
26533
+ }
26534
+ },
26535
+ "actionType": "download"
26536
+ }
26537
+ ],
26538
+ "weight": 0
26539
+ }
26540
+ }
26541
+ };
26542
+ }
26543
+
26396
26544
  }
26397
- var obj = superProps
26398
- ? Object.create(superProps, __assign(__assign({}, properties), { __super: {
26399
- value: superProps,
26400
- writable: false,
26401
- enumerable: false
26402
- } }))
26403
- : Object.create(Object.prototype, properties);
26404
- props &&
26405
- isObject(props) &&
26406
- Object.keys(props).forEach(function (key) { return (obj[key] = props[key]); });
26407
- return obj;
26408
- }
26409
- function cloneObject(target, persistOwnProps) {
26410
- if (persistOwnProps === void 0) { persistOwnProps = true; }
26411
- var obj = target && target.__super
26412
- ? Object.create(target.__super, {
26413
- __super: {
26414
- value: target.__super,
26415
- writable: false,
26416
- enumerable: false
26417
- }
26418
- })
26419
- : Object.create(Object.prototype);
26420
- persistOwnProps &&
26421
- target &&
26422
- Object.keys(target).forEach(function (key) { return (obj[key] = target[key]); });
26423
- return obj;
26424
- }
26425
- function isObject(obj) {
26426
- var typename = typeof obj;
26427
- return (obj &&
26428
- typename !== 'string' &&
26429
- typename !== 'number' &&
26430
- typename !== 'boolean' &&
26431
- typename !== 'function' &&
26432
- !Array.isArray(obj));
26433
- }
26434
-
26435
- /*
26436
- * @Author: baozhoutao@steedos.com
26437
- * @Date: 2022-07-05 15:55:39
26438
- * @LastEditors: liaodaxue
26439
- * @LastEditTime: 2023-10-20 11:38:25
26440
- * @Description:
26441
- */
26442
26545
 
26443
- let UI_SCHEMA_CACHE = {};
26546
+ columns.push(column);
26547
+
26444
26548
 
26445
- let UISchemaFunction;
26549
+ return columns;
26550
+ }
26446
26551
 
26447
- if('undefined' != typeof window){
26448
- if(!window.UI_SCHEMA_CACHE){
26449
- window.UI_SCHEMA_CACHE = UI_SCHEMA_CACHE;
26552
+ function getDefaultParams(options){
26553
+ return {
26554
+ perPage: options.top || options.perPage || config.listView.perPage
26450
26555
  }
26451
- UI_SCHEMA_CACHE = window.UI_SCHEMA_CACHE;
26452
26556
  }
26453
26557
 
26454
- const setUISchemaCache = (key, value) => {
26455
- UI_SCHEMA_CACHE[key] = value;
26456
- };
26457
-
26458
- const getUISchemaCache = (key) => {
26459
- return lodash.exports.cloneDeep(UI_SCHEMA_CACHE[key]);
26460
- };
26461
-
26462
- const hasUISchemaCache = (key) => {
26463
- return lodash.exports.has(UI_SCHEMA_CACHE, key);
26464
- };
26558
+ function getButtonVisibleOn(button){
26559
+ let visible= button.visible;
26465
26560
 
26466
- function getListViewColumns(listView, formFactor) {
26467
- let listViewColumns = [];
26468
- if (formFactor === "SMALL") {
26469
- listViewColumns = !lodash.exports.isEmpty(listView.mobile_columns)
26470
- ? listView.mobile_columns
26471
- : lodash.exports.slice(listView.columns, 0, 4);
26472
- } else {
26473
- listViewColumns = listView.columns;
26561
+ if(button._visible){
26562
+ visible = button._visible;
26474
26563
  }
26475
- return listViewColumns;
26476
- }
26477
- function getListViewSort(listView) {
26478
- let sort = '';
26479
- if(listView && listView.sort && listView.sort.length){
26480
- lodash.exports.each(listView.sort,function(item,index){
26481
- if(lodash.exports.isArray(item)){
26482
- const field_name = item[0];
26483
- const order = item[1] || '';
26484
- let sortStr = field_name + ' ' + order;
26485
- sortStr = index > 0 ? ','+sortStr : sortStr;
26486
- sort += sortStr;
26487
- }else {
26488
- let sortStr = item.field_name + ' ' + item.order;
26489
- sortStr = index > 0 ? ','+sortStr : sortStr;
26490
- sort += sortStr;
26491
- }
26492
- });
26564
+
26565
+ if(lodash.exports.isBoolean(visible)){
26566
+ visible = visible.toString();
26493
26567
  }
26494
- return sort;
26495
- }
26496
- function getListViewFilter(listView){
26497
- if(!listView){
26498
- return ;
26568
+
26569
+ if(visible){
26570
+ // if(visible.indexOf("Meteor.") > 0 || visible.indexOf("Creator.") > 0 || visible.indexOf("Session.") > 0){
26571
+ // console.warn('无效的visible', visible)
26572
+ // return 'false';
26573
+ // }
26574
+ if(visible.trim().startsWith('function')){
26575
+ return `${visible}(objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
26576
+ }
26577
+ return visible;
26499
26578
  }
26500
- try {
26501
- const userId = getUserId();
26502
- let filters = listView.filters;
26503
- if(listView.filter_scope === 'mine'){
26504
- if(___default.isEmpty(filters)){
26505
- filters = [["owner", "=", userId]];
26506
- }else {
26507
- if(___default.isString(filters) && ___default.startsWith(___default.trim(filters), "function")){
26508
- filters = new Function(`return ${filters}`);
26509
- filters = filters();
26510
- }
26511
- if(___default.isArray(filters)){
26512
- filters.push(["owner", "=", userId]);
26513
- }else {
26514
- console.debug(`listView filters is not array`, listView);
26515
- throw new Error('filters is not array')
26516
- }
26517
- }
26518
- };
26519
- return filters;
26520
- } catch (error) {
26521
- console.error(error);
26579
+
26580
+ if(button.type === 'amis_button'){
26581
+ const amisSchema = button.amis_schema;
26582
+ if(amisSchema && amisSchema.body && amisSchema.body.length > 0){
26583
+ const btn1 = amisSchema.body[0];
26584
+ return btn1.visibleOn
26585
+ }
26522
26586
  }
26523
26587
  }
26524
26588
 
26525
- function formatUISchemaCache(objectName, uiSchema){
26526
- setUISchemaCache(objectName, uiSchema);
26527
- lodash.exports.each(uiSchema.fields, (field)=>{
26528
- try {
26529
- if(field.type === "lookup" && field._reference_to && ___default.isString(field._reference_to)){
26530
- field.reference_to = eval(`(${field._reference_to})`)();
26531
- }
26532
- } catch (exception) {
26533
- field.reference_to = undefined;
26534
- console.error(exception);
26535
- }
26536
- });
26537
- lodash.exports.each(uiSchema.list_views, (v, k)=>{
26538
- v.name = k;
26539
- if(!lodash.exports.has(v, 'columns')){
26540
- v.columns = uiSchema.list_views.all.columns;
26589
+ async function getTableOperation(ctx){
26590
+ const buttons = ctx.buttons;
26591
+ const operationButtons = [];
26592
+ lodash.exports.each(buttons, (button)=>{
26593
+ if(lodash.exports.isBoolean(button.visible)){
26594
+ button.visible = button.visible.toString();
26541
26595
  }
26542
- });
26543
- }
26596
+ // operationButtons.push({
26597
+ // type: 'button',
26598
+ // label: button.label,
26599
+ // visibleOn: button.visible ? `${button.visible}` : (button._visible ? `${button._visible}` : null),
26600
+ // onEvent: {
26601
+ // click: {
26602
+ // actions: []
26603
+ // }
26604
+ // }
26605
+ // })
26544
26606
 
26545
- async function getUISchema(objectName, force) {
26546
- if (!objectName) {
26547
- return;
26548
- }
26549
- if (hasUISchemaCache(objectName) && !force) {
26550
- return getUISchemaCache(objectName);
26607
+ operationButtons.push({
26608
+ type: 'steedos-object-button',
26609
+ name: button.name,
26610
+ objectName: button.objectName,
26611
+ visibleOn: getButtonVisibleOn(button),
26612
+ className: 'antd-Button--default'
26613
+ });
26614
+ });
26615
+ if(operationButtons.length < 1){
26616
+ return ;
26551
26617
  }
26552
- let uiSchema = null;
26553
- try {
26554
- if(UISchemaFunction);
26555
- else {
26556
- const url = `/service/api/@${objectName.replace(/\./g, "_")}/uiSchema`;
26557
- uiSchema = await fetchAPI(url, { method: "get" });
26558
- }
26559
- if(!uiSchema){
26560
- return ;
26561
- }
26562
- formatUISchemaCache(objectName, uiSchema);
26563
- } catch (error) {
26564
- console.error(`getUISchema`, objectName, error);
26565
- setUISchemaCache(objectName, null);
26618
+ return {
26619
+ type: 'operation',
26620
+ label: "&nbsp;",
26621
+ fixed: 'right',
26622
+ labelClassName: 'text-center',
26623
+ className: 'text-center steedos-listview-operation w-10',
26624
+ buttons: [
26625
+ {
26626
+ "type": "steedos-dropdown-button",
26627
+ "label": "xxx",
26628
+ "buttons": operationButtons,
26629
+ "placement": "bottomRight",
26630
+ "overlayClassName": "shadow !min-w-[160px]",
26631
+ "trigger": ["click"],
26632
+ "id": "u:c2140a365019",
26633
+ onOpenApi: {
26634
+ url: `\${context.rootUrl}/service/api/@\${objectName}/recordPermissions/\${_id}`,
26635
+ method: "get",
26636
+ requestAdaptor: "api.data={}; return api;",
26637
+ headers: {
26638
+ Authorization: "Bearer ${context.tenantId},${context.authToken}"
26639
+ },
26640
+ adaptor: `
26641
+ payload = {
26642
+ record: {
26643
+ recordPermissions: payload
26644
+ }
26645
+ };
26646
+ return payload;
26647
+ `,
26648
+ }
26649
+ }
26650
+ ]
26566
26651
  }
26567
- return getUISchemaCache(objectName);
26568
26652
  }
26569
26653
 
26570
- function getUISchemaSync(objectName, force) {
26571
- if (!objectName) {
26572
- return;
26573
- }
26574
- if (hasUISchemaCache(objectName) && !force) {
26575
- return getUISchemaCache(objectName);
26576
- }
26577
- let uiSchema = null;
26578
- try {
26579
-
26580
- const url = `/service/api/@${objectName.replace(/\./g, "_")}/uiSchema`;
26581
- uiSchema = Steedos.authRequest(url, {
26582
- type: 'GET',
26583
- async: false,
26584
- });
26585
-
26586
- if(!uiSchema){
26587
- return ;
26654
+ async function getDefaultCrudCard(columns, options) {
26655
+ let labelFieldName = options?.labelFieldName || "name";
26656
+ let titleColumn, bodyColumns = [];
26657
+ columns.forEach(function (item) {
26658
+ delete item.quickEdit;
26659
+ delete item.width;
26660
+ if (item.name === labelFieldName) {
26661
+ titleColumn = item;
26588
26662
  }
26589
- formatUISchemaCache(objectName, uiSchema);
26590
- } catch (error) {
26591
- console.error(`getUISchema`, objectName, error);
26592
- setUISchemaCache(objectName, null);
26663
+ else {
26664
+ if (item.name !== "_index") {
26665
+ bodyColumns.push(item);
26666
+ }
26667
+ }
26668
+ });
26669
+ let card = {
26670
+ "header": {
26671
+ "title": titleColumn.tpl
26672
+ },
26673
+ body: bodyColumns,
26674
+ // useCardLabel: false,
26675
+ toolbar: []
26676
+ };
26677
+ let hideToolbarOperation = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
26678
+ if(!hideToolbarOperation){
26679
+ let toolbarOperation = await getTableOperation(options);
26680
+ if (toolbarOperation) {
26681
+ toolbarOperation.className += " inline-block w-auto";
26682
+ }
26683
+ card.toolbar.push(toolbarOperation);
26593
26684
  }
26594
- return getUISchemaCache(objectName);
26685
+ return card;
26595
26686
  }
26596
26687
 
26597
- // 获取列表视图
26598
- async function getListSchema(
26599
- appName,
26600
- objectName,
26601
- listViewName,
26602
- ctx = {}
26603
- ) {
26604
- const uiSchema = await getUISchema(objectName);
26605
- if(!uiSchema){
26606
- return {}
26688
+ async function getTableSchema(fields, options){
26689
+ if(!options){
26690
+ options = {};
26607
26691
  }
26608
- const listView = lodash.exports.find(
26609
- uiSchema.list_views,
26610
- (listView, name) => {
26611
- // 传入listViewName空值则取第一个
26612
- if(!listViewName){
26613
- listViewName = name;
26614
- }
26615
- return name === listViewName || listView._id === listViewName;
26616
- }
26617
- );
26692
+ let { isLookup, hiddenColumnOperation } = options;
26693
+ const defaults = options.defaults;
26694
+ const listSchema = (defaults && defaults.listSchema) || {};
26618
26695
 
26619
- if (!listView) {
26620
- return { uiSchema };
26696
+ let columns = [];
26697
+ let useMobileColumns = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
26698
+ if(isLookup){
26699
+ // 在lookup手机端列表模式调式好之前不使用getMobileTableColumns
26700
+ useMobileColumns = false;
26621
26701
  }
26622
-
26623
- // 直接返回自定义的列表视图schema
26624
- if(listView.enable_amis_schema && listView.amis_schema){
26625
- const amisSchema = lodash.exports.isString(listView.amis_schema) ? JSON.parse(listView.amis_schema) : listView.amis_schema;
26626
- return {
26627
- uiSchema,
26628
- isCustomAmisSchema: true,
26629
- amisSchema
26630
- };
26702
+ if(listSchema.mode && listSchema.mode !== "table"){
26703
+ // 如果指定的mode,则不走我们内置的手机端列表效果,使用steedos组件内部开发的默认card/list效果,或者由用户自己实现card/list模式的crud列表
26704
+ useMobileColumns = false;
26631
26705
  }
26632
-
26633
- let listViewColumns = getListViewColumns(listView, ctx.formFactor);
26634
- let sort = getListViewSort(listView);
26635
- let listviewFilter = getListViewFilter(listView);
26636
- let listview_filters = listView && listView._filters;
26637
- // 返回 calendar 组件
26638
- if(listView.type === "calendar"){
26639
- const amisSchema = {
26640
- "type": "steedos-object-calendar",
26641
- "objectApiName": objectName,
26642
- "filters": listviewFilter,
26643
- "filtersFunction": listview_filters,
26644
- "sort": sort,
26645
- ...listView.options
26646
- };
26647
- return {
26648
- uiSchema,
26649
- isCalendar: true,
26650
- amisSchema
26651
- };
26706
+ if(useMobileColumns){
26707
+ columns = await getMobileTableColumns(fields, options);
26652
26708
  }
26709
+ else {
26710
+ columns = await getTableColumns(fields, options);
26653
26711
 
26654
- const defaults = ctx.defaults || {};
26655
-
26656
- // // 未自定义header 且显示header的时候, 使用系统header
26657
- // if(!defaults.headerSchema && ctx.showHeader){
26658
- // defaults.headerSchema = getObjectListHeader(uiSchema, listViewName);
26659
- // }
26660
-
26661
- // // 如果不显示header,则清理掉
26662
- // if(!ctx.showHeader){
26663
- // defaults.headerSchema = null;
26664
- // }
26665
-
26666
- defaults.headerSchema = null;
26667
-
26668
- /**
26669
- * 本次存储代码段
26670
- */
26671
- try {
26672
- const listViewPropsStoreKey = location.pathname + "/crud";
26673
- let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
26674
- /**
26675
- * localListViewProps规范来自crud请求api中api.data.$self参数值的。
26676
- * 比如:{"perPage":20,"page":1,"__searchable__name":"7","__searchable__between__n1__c":[null,null],"filter":[["name","contains","a"]]}
26677
- * __searchable__...:顶部放大镜搜索条件
26678
- * filter:右侧过滤器
26679
- * perPage:每页条数
26680
- * page:当前页码
26681
- * orderBy:排序字段
26682
- * orderDir:排序方向
26683
- */
26684
- if (localListViewProps) {
26685
- localListViewProps = JSON.parse(localListViewProps);
26686
- // localListViewProps.perPage = 3;
26687
- let listSchema = {};
26688
- if(localListViewProps.orderBy){
26689
- listSchema.orderBy = localListViewProps.orderBy;
26690
- }
26691
- if(localListViewProps.orderDir){
26692
- listSchema.orderDir = localListViewProps.orderDir;
26712
+ if(listSchema.mode === "cards"){
26713
+ let card = listSchema.card;
26714
+ if(!card){
26715
+ card = await getDefaultCrudCard(columns, options);
26716
+ }
26717
+ return {
26718
+ mode: "cards",
26719
+ perPageAvailable: [5, 10, 20, 50, 100, 500],
26720
+ name: "thelist",
26721
+ headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
26722
+ className: "",
26723
+ draggable: false,
26724
+ defaultParams: getDefaultParams(options),
26725
+ card: card,
26726
+ syncLocation: false,
26727
+ keepItemSelectionOnPageChange: true,
26728
+ checkOnItemClick: isLookup ? true : false,
26729
+ labelTpl: `\${${options.labelFieldName}}`,
26730
+ autoFillHeight: false, // 自动高度效果不理想,先关闭
26731
+ columnsTogglable: false
26732
+ }
26693
26733
  }
26694
26734
 
26695
- if(localListViewProps.perPage){
26696
- listSchema.defaultParams = {
26697
- perPage: localListViewProps.perPage
26698
- };
26735
+ if(!isLookup && !hiddenColumnOperation){
26736
+ columns.push(await getTableOperation(options));
26699
26737
  }
26700
- defaults.listSchema = lodash.exports.defaultsDeep({}, listSchema, defaults.listSchema || {});
26701
- }
26702
- }
26703
- catch (ex) {
26704
- console.error("本地存储中crud参数解析异常:", ex);
26705
26738
  }
26706
26739
 
26707
- ctx.defaults = defaults;
26708
-
26709
- if (listViewName == "recent") {
26710
- listview_filters = `
26711
- function(filters, data) {
26712
- var result = Steedos.authRequest('/graphql', {
26713
- type: 'POST',
26714
- async: false,
26715
- data: JSON.stringify({
26716
- query: '{object_recent_viewed(filters: [["record.o","=","' + data.objectName + '"],["space","=","' + data.context.tenantId + '"],["owner","=","' + data.context.userId + '"]],sort:"modified desc",top:50){ _id,record} }'
26717
- }),
26718
- });
26719
- var _ids = []
26720
- result.data.object_recent_viewed.forEach(function (item) {
26721
- _ids = _ids.concat(item.record.ids)
26722
- })
26723
- return ["_id", "=", _ids];
26724
- }
26725
- `;
26726
- }
26727
- const amisSchema = {
26728
- "type": "steedos-object-table",
26729
- "objectApiName": objectName,
26730
- "columns": listViewColumns,
26731
- "extraColumns": listView.extra_columns,
26732
- "filters": listviewFilter,
26733
- "filtersFunction": listview_filters,
26734
- "sort": sort,
26735
- "ctx": ctx,
26736
- "requestAdaptor": listView.requestAdaptor || ctx.requestAdaptor,
26737
- "adaptor": listView.adaptor || ctx.adaptor,
26738
- "headerToolbarItems": ctx.headerToolbarItems,
26739
- "filterVisible": ctx.filterVisible,
26740
- "rowClassNameExpr": ctx.rowClassNameExpr,
26741
- "crudDataFilter": ctx.crudDataFilter,
26742
- "onCrudDataFilter": ctx.onCrudDataFilter
26743
- };
26744
- // console.log(`getListSchema===>`,amisSchema)
26745
26740
  return {
26746
- uiSchema,
26747
- amisSchema,
26748
- };
26749
- }
26750
-
26751
-
26752
- if(typeof window != 'undefined'){
26753
- window.getUISchema = getUISchema;
26754
- window.getUISchemaSync = getUISchemaSync;
26755
- window.getListSchema = getListSchema;
26741
+ mode: "table",
26742
+ perPageAvailable: [5, 10, 20, 50, 100, 500],
26743
+ name: "thelist",
26744
+ headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
26745
+ className: "",
26746
+ draggable: false,
26747
+ defaultParams: getDefaultParams(options),
26748
+ columns: columns,
26749
+ syncLocation: false,
26750
+ keepItemSelectionOnPageChange: true,
26751
+ checkOnItemClick: isLookup ? true : false,
26752
+ labelTpl: `\${${options.labelFieldName}}`,
26753
+ autoFillHeight: false, // 自动高度效果不理想,先关闭
26754
+ columnsTogglable: false,
26755
+ }
26756
26756
  }
26757
26757
 
26758
26758
  function useCombinedRefs(...refs) {