@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.
@@ -53851,6 +53851,53 @@ var funcToString = funcProto.toString;
53851
53851
  /** Used to infer the `Object` constructor. */
53852
53852
  funcToString.call(Object);
53853
53853
 
53854
+ /*
53855
+ * @Author: baozhoutao@steedos.com
53856
+ * @Date: 2022-08-16 17:02:08
53857
+ * @LastEditors: baozhoutao@steedos.com
53858
+ * @LastEditTime: 2023-06-20 13:50:15
53859
+ * @Description:
53860
+ */
53861
+
53862
+
53863
+ const Router = {
53864
+ getTabDisplayAs(tab_id){
53865
+ var urlSearch = new URLSearchParams(document.location.search);
53866
+ if(urlSearch.has('display')){
53867
+ return urlSearch.get('display')
53868
+ }
53869
+ const key = `tab_${tab_id}_display`;
53870
+ // const key = `page_display`;
53871
+ const value = localStorage.getItem(key);
53872
+ return value ? value : 'grid'
53873
+ },
53874
+
53875
+ setTabDisplayAs(tab_id, displayAs){
53876
+ const key = `tab_${tab_id}_display`;
53877
+ localStorage.setItem(key, displayAs);
53878
+ },
53879
+ getAppPath({formFactor, appId}){
53880
+ return `/app/${appId}`;
53881
+ },
53882
+ getPagePath(){
53883
+ //TODO
53884
+ },
53885
+ getObjectListViewPath({formFactor, appId, objectName, listViewName}){
53886
+ return `/app/${appId}/${objectName}/grid/${listViewName}`;
53887
+ },
53888
+ getObjectDetailPath(props){
53889
+ const {formFactor, appId, objectName, recordId, listViewName, _templateType} = props;
53890
+ if(_templateType === 'JavaScript'){
53891
+ return `/app/${appId}/${objectName}/view/${recordId}?side_object=<%=item.objectName%>&side_listview_id=<%=item.listName%>`;
53892
+ }
53893
+ return `/app/${appId}/${objectName}/view/${recordId}?side_object=\${objectName}&side_listview_id=\${listName}`;
53894
+ },
53895
+ getObjectRelatedViewPath({formFactor, appId, masterObjectName, masterRecordId, objectName, foreignKey}){
53896
+ return `/app/${appId}/${masterObjectName}/${masterRecordId}/${objectName}/grid?related_field_name=${foreignKey}`;
53897
+ },
53898
+
53899
+ };
53900
+
53854
53901
  const getBuilderContext = ()=>{
53855
53902
  if(typeof window === "undefined"){
53856
53903
  return {};
@@ -53925,437 +53972,109 @@ function getRootUrl(defaultRootUrl){
53925
53972
  return defaultRootUrl || '';
53926
53973
  }
53927
53974
 
53928
- /*
53929
- * @Author: baozhoutao@steedos.com
53930
- * @Date: 2022-08-16 17:02:08
53931
- * @LastEditors: baozhoutao@steedos.com
53932
- * @LastEditTime: 2023-06-20 13:50:15
53933
- * @Description:
53934
- */
53935
-
53936
-
53937
- const Router = {
53938
- getTabDisplayAs(tab_id){
53939
- var urlSearch = new URLSearchParams(document.location.search);
53940
- if(urlSearch.has('display')){
53941
- return urlSearch.get('display')
53942
- }
53943
- const key = `tab_${tab_id}_display`;
53944
- // const key = `page_display`;
53945
- const value = localStorage.getItem(key);
53946
- return value ? value : 'grid'
53947
- },
53948
-
53949
- setTabDisplayAs(tab_id, displayAs){
53950
- const key = `tab_${tab_id}_display`;
53951
- localStorage.setItem(key, displayAs);
53952
- },
53953
- getAppPath({formFactor, appId}){
53954
- return `/app/${appId}`;
53955
- },
53956
- getPagePath(){
53957
- //TODO
53958
- },
53959
- getObjectListViewPath({formFactor, appId, objectName, listViewName}){
53960
- return `/app/${appId}/${objectName}/grid/${listViewName}`;
53961
- },
53962
- getObjectDetailPath(props){
53963
- const {formFactor, appId, objectName, recordId, listViewName, _templateType} = props;
53964
- if(_templateType === 'JavaScript'){
53965
- return `/app/${appId}/${objectName}/view/${recordId}?side_object=<%=item.objectName%>&side_listview_id=<%=item.listName%>`;
53975
+ async function getFieldsTemplate(fields, display){
53976
+ let expandFields = [];
53977
+ if(display != false){
53978
+ display = true;
53979
+ }
53980
+ let fieldsName = ['_id'];
53981
+ let displayFields = [];
53982
+ let fieldsArr = [];
53983
+ if(lodash.exports.isArray(fields)){
53984
+ fieldsArr = fields;
53985
+ }else {
53986
+ fieldsArr = lodash.exports.values(fields);
53987
+ }
53988
+ for (const field of fieldsArr) {
53989
+ //graphql 的 ui\display 中使用的字段需要先在query中查询. 否则会返回null
53990
+ if(field.expand){
53991
+ expandFields.push(field);
53992
+ }else {
53993
+ if(field.name.indexOf('.') < 0){
53994
+ if(display && (field.type == 'lookup' || field.type == 'master_detail')){
53995
+ fieldsName.push(`${field.name}`);
53996
+ displayFields.push(`${field.name}`);
53997
+ }else {
53998
+ fieldsName.push( field.alias ? `${field.alias}:${field.name}` : field.name);
53999
+ }
54000
+ if(lodash.exports.includes(['time','date','datetime','boolean','number','currency'], field.type)){
54001
+ fieldsName.push(`${field.name}`);
54002
+ }
54003
+ if(lodash.exports.includes(['percent','time','filesize','date','datetime','boolean','number','currency', 'select', 'file', 'image', 'avatar', 'formula', 'summary', 'object', 'grid'], field.type)){
54004
+ displayFields.push(`${field.name}`);
54005
+ }
54006
+ }else {
54007
+ objectFieldName = field.name.split('.')[0];
54008
+ fieldsName.push(objectFieldName);
54009
+ displayFields.push(objectFieldName);
54010
+ }
53966
54011
  }
53967
- return `/app/${appId}/${objectName}/view/${recordId}?side_object=\${objectName}&side_listview_id=\${listName}`;
53968
- },
53969
- getObjectRelatedViewPath({formFactor, appId, masterObjectName, masterRecordId, objectName, foreignKey}){
53970
- return `/app/${appId}/${masterObjectName}/${masterRecordId}/${objectName}/grid?related_field_name=${foreignKey}`;
53971
- },
53972
-
53973
- };
53974
-
53975
- /*
53976
- * @Author: baozhoutao@steedos.com
53977
- * @Date: 2022-07-20 16:29:22
53978
- * @LastEditors: liaodaxue
53979
- * @LastEditTime: 2023-09-11 17:19:53
53980
- * @Description:
53981
- */
53982
-
53983
- function getImageFieldUrl(url) {
53984
- if (window.Meteor && window.Meteor.isCordova != true) {
53985
- // '//'的位置
53986
- const doubleSlashIndex = url.indexOf('//');
53987
- const urlIndex = url.indexOf('/', doubleSlashIndex + 2);
53988
- const rootUrl = url.substring(urlIndex);
53989
- return rootUrl;
53990
- }
53991
- return url;
53992
- }
54012
+ }
53993
54013
 
53994
- if(typeof window != 'undefined'){
53995
- window.getImageFieldUrl = getImageFieldUrl;
53996
- }
54014
+ displayFields = lodash.exports.uniq(displayFields);
54015
+ fieldsName = lodash.exports.uniq(fieldsName);
54016
+ let expandFieldsQuery = "";
54017
+ if(expandFields.length > 0){
54018
+ lodash.exports.each(expandFields, function(field){
54019
+ expandFieldsQuery = expandFieldsQuery + `${field.expandInfo.fieldName}__expand{${field.expandInfo.displayName}}`;
54020
+ });
54021
+ }
53997
54022
 
53998
- function getContrastColor(bgColor) {
53999
- var backgroundColor = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor;
54000
- var r = parseInt(backgroundColor.substr(0, 2), 16);
54001
- var g = parseInt(backgroundColor.substr(2, 2), 16);
54002
- var b = parseInt(backgroundColor.substr(4, 2), 16);
54003
- var brightness = (r * 299 + g * 587 + b * 114) / 1000;
54004
- return brightness < 128 ? "#ffffff" : "#000000";
54023
+ if(displayFields.length > 0){
54024
+ return `${fieldsName.join(',')},${expandFieldsQuery},_display:_ui{${displayFields.join(',')}}`;
54025
+ }
54026
+ return lodash.exports.trimEnd(`${fieldsName.join(' ')},${expandFieldsQuery}`, ",")
54005
54027
  }
54006
54028
 
54007
- function getLookupListView(refObjectConfig) {
54008
- if(!refObjectConfig){
54009
- return null;
54010
- }
54011
- const listNameAll = "all";
54012
- const listNameLookup = "lookup";
54013
- let listViewAll, listViewLookup;
54029
+ async function getFindQuery(object, recordId, fields, options){
54030
+ let limit = options.limit || 10;
54031
+ let queryOptions = `(top: ${limit})`;
54032
+ if(recordId){
54033
+ queryOptions = `(filters:["_id", "=", "${recordId}"], top: ${limit})`;
54034
+ }
54035
+ let alias = "data";
54036
+ if(options){
54037
+ if(options.alias){
54038
+ alias = options.alias;
54039
+ }
54014
54040
 
54015
- _.each(
54016
- refObjectConfig.list_views,
54017
- (view, name) => {
54018
- if (name === listNameAll) {
54019
- listViewAll = view;
54020
- if(!listViewAll.name){
54021
- listViewAll.name = name;
54041
+ if(options.filters){
54042
+ queryOptions = `(filters:${options.filters})`;
54022
54043
  }
54023
- }
54024
- else if (name === listNameLookup) {
54025
- listViewLookup = view;
54026
- if(!listViewLookup.name){
54027
- listViewLookup.name = name;
54044
+ if(options.queryOptions){
54045
+ queryOptions = `(${options.queryOptions})`;
54028
54046
  }
54029
- }
54030
54047
  }
54031
- );
54032
- let listView = listViewLookup || listViewAll;
54033
- return listView;
54034
- }
54035
-
54036
- function getNumberTpl(field){
54037
- return `<span>\${_display.${field.name}}</span>`
54038
- }
54039
-
54040
- function getTimeTpl(field){
54041
- return `<span>\${_display.${field.name}}</span>`
54042
- }
54043
-
54044
- function getDateTpl(field){
54045
- return `<span>\${_display.${field.name}}</span>`
54046
- }
54048
+ var treeFields = '';
54049
+ if(object.enable_tree && lodash.exports.includes(lodash.exports.keys(object.fields), 'parent') && lodash.exports.includes(lodash.exports.keys(object.fields), 'children')){
54050
+ treeFields = ',parent,children';
54051
+ }
54047
54052
 
54053
+ var cfsFields = '';
54054
+ if(object.name === 'cms_files'){
54055
+ cfsFields = ',versions';
54056
+ }
54048
54057
 
54049
- function getDateTimeTpl(field){
54050
- return `<span>\${_display.${field.name}}</span>`
54051
- }
54058
+ const countQuery = options.count === false ? "" : `,count:${object.name}__count(filters:{__filters})`;
54059
+ // const moreQuerie = options.moreQueries?.length ? ("," + options.moreQueries.map(function(item){
54060
+ // // 把最外层的{}去除
54061
+ // return item.replace(/^{/,"").replace(/}$/,"");
54062
+ // }).join(",")) : "";
54052
54063
 
54053
- function getUiFieldTpl(field){
54054
- return `<span>\${_display.${field.name}}</span>`
54064
+ return {
54065
+ orderBy: "${orderBy}",
54066
+ orderDir: "${orderDir}",
54067
+ pageNo: "${page}",
54068
+ pageSize: "${perPage}",
54069
+ query: `{${alias}:${object.name}${queryOptions}{${await getFieldsTemplate(fields, options.expand)}${treeFields}${cfsFields}}${countQuery}}`
54070
+ }
54055
54071
  }
54056
54072
 
54057
- function getUiFileSizeTpl(field){
54058
- return `<span>\${_display.${field.name}}</span>`
54059
- }
54060
-
54061
- //TODO 处理name字段
54062
- async function getRefObjectNameFieldName(field){
54063
- const refUiSchema = await getUISchema(field.reference_to);
54064
- const NAME_FIELD_KEY = refUiSchema.NAME_FIELD_KEY || 'name';
54065
- return NAME_FIELD_KEY;
54066
- }
54067
-
54068
- function getSelectTpl(field){
54069
- return `<span>\${_display.${field.name}}</span>`
54070
- }
54071
- function getSelectMap(selectOptions){
54072
- let map = {};
54073
- lodash.exports.forEach(selectOptions,(option)=>{
54074
- const optionValue = option.value + '';
54075
- const optionColor = option.color + '';
54076
- if(optionColor){
54077
- const background = optionColor.charAt(0) === '#' ? optionColor : '#'+optionColor;
54078
- const color = getContrastColor(background);
54079
- const optionColorStyle = 'background:'+background+';color:'+color+';line-height:1.5rem';
54080
- map[optionValue] = `<span class="rounded-xl px-2 py-1" style='${optionColorStyle}'>${option.label}</span>`;
54081
- }else {
54082
- map[optionValue] = option.label;
54083
- }
54084
- });
54085
- return map;
54086
- }
54087
-
54088
- function getNameTplUrl(field, ctx){
54089
- if(ctx.objectName === 'cms_files'){
54090
- return `\${context.rootUrl}/api/files/files/\${versions[0]}?download=true`
54091
- }
54092
- const href = Router.getObjectDetailPath({
54093
- ...ctx, formFactor: ctx.formFactor, appId: "${appId}", objectName: ctx.objectName || "${objectName}", recordId: `\${${ctx.idFieldName}}`
54094
- });
54095
- return href;
54096
- }
54097
-
54098
- function getNameTpl(field, ctx){
54099
- const href = getNameTplUrl(field, ctx);
54100
- let linkTarget = "";
54101
- if(ctx && ctx.isLookup){
54102
- linkTarget = "target='_blank'";
54103
- }
54104
- return `<a href="${href}" ${linkTarget}>\${${field.name}}</a>`
54105
- }
54106
-
54107
- function getRelatedFieldTpl(field, ctx){
54108
- let tpl = '';
54109
- if(!field.reference_to && (field.optionsFunction || field._optionsFunction || field.options)){
54110
- if(field.isTableField){
54111
- return `\${${field.name}}`
54112
- }else {
54113
- return `\${${field.name}__label}`
54114
- }
54115
- }
54116
-
54117
- let linkTarget = "";
54118
- if(ctx && ctx.isLookup){
54119
- linkTarget = "target='_blank'";
54120
- }
54121
-
54122
- const onlyDisplayLookLabel = ctx.onlyDisplayLookLabel;
54123
-
54124
- let fieldDataStrTpl = `data._display.${field.name}`;
54125
-
54126
- if(field.isTableField){
54127
- fieldDataStrTpl = `data.${field.name}`;
54128
- }
54129
-
54130
- if(_.isString(field.reference_to) || !field.reference_to){
54131
- if(field.multiple){
54132
- let labelTpl = `<%=item.label%>`;
54133
- if(!onlyDisplayLookLabel){
54134
- const href = Router.getObjectDetailPath({
54135
- formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
54136
- });
54137
- labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
54138
- }
54139
- tpl = `
54140
- <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item,index) { %> <% if(index>0 && index<${fieldDataStrTpl}.length){ %> , <% } %> ${labelTpl} <% }); %><% } %>
54141
- `;
54142
- }else {
54143
- let labelTpl = `\${_display.${field.name}.label}`;
54144
- let objectNameTpl = `\${_display.${field.name}.objectName}`;
54145
- let recordIdTpl = `\${_display.${field.name}.value}`;
54146
- if(field.isTableField){
54147
- labelTpl = `\${${field.name}.label}`;
54148
- objectNameTpl = `\${${field.name}.objectName}`;
54149
- recordIdTpl = `\${${field.name}.value}`;
54150
- }
54151
- if(!onlyDisplayLookLabel){
54152
- const href = Router.getObjectDetailPath({
54153
- formFactor: ctx.formFactor, appId: "${appId}", objectName: `${objectNameTpl}`, recordId: `${recordIdTpl}`
54154
- });
54155
- labelTpl = `<a href="${href}" ${linkTarget}>${labelTpl}</a>`;
54156
- }
54157
- tpl = labelTpl;
54158
- }
54159
-
54160
-
54161
- }else {
54162
- let labelTpl = `<%=item.label%>`;
54163
- if(!onlyDisplayLookLabel){
54164
- const href = Router.getObjectDetailPath({
54165
- formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
54166
- });
54167
- labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
54168
- }
54169
- tpl = `
54170
- <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item) { %> ${labelTpl} <% }); %><% } %>
54171
- `;
54172
- }
54173
- return tpl
54174
- }
54175
-
54176
- async function getLookupTpl(field, ctx){
54177
- if(!field.reference_to){
54178
- return getSelectTpl(field)
54179
- }
54180
- const NAME_FIELD_KEY = await getRefObjectNameFieldName(field);
54181
- if(field.multiple){
54182
- const href = Router.getObjectDetailPath({
54183
- formFactor: ctx.formFactor, appId: ctx.appId, objectName: field.reference_to, recordId: `<%=item._id%>`, _templateType: "JavaScript"
54184
- });
54185
- return `
54186
- <% if (data.${field.name} && data.${field.name}.length) { %><% data.${field.name}.forEach(function(item) { %> <a href="${href}"><%=item.${NAME_FIELD_KEY}%></a> <% }); %><% } %>
54187
- `
54188
- }else {
54189
- const href = Router.getObjectDetailPath({
54190
- formFactor: ctx.formFactor, appId: ctx.appId, objectName: field.reference_to, recordId: `\${${field.name}._id}`
54191
- });
54192
- return `<a href="${href}">\${${field.name}.${NAME_FIELD_KEY}}</a>`
54193
- }
54194
-
54195
- }
54196
-
54197
- function getSwitchTpl(field){
54198
- let fieldDataStrTpl = `data._display.${field.name}`;
54199
- if(field.isTableField){
54200
- fieldDataStrTpl = `data.${field.name}`;
54201
- }
54202
- return `<% if (data.${field.name}) { %>
54203
- <span class="slds-icon_container slds-icon-utility-check slds-current-color" title="<%=${fieldDataStrTpl}%>">
54204
- <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>
54205
- </span>
54206
- <% } %>`
54207
- }
54208
-
54209
- function getPasswordTpl(field){
54210
- return `<% if (data.${field.name}) { %>
54211
- <span>······</span>
54212
- <% } %>`
54213
- }
54214
-
54215
- function getLocationTpl(field){
54216
- return `\${${field.name} ? ${field.name}.address : ''}`
54217
- }
54218
-
54219
- async function getFieldTpl (field, options){
54220
- if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLookLabel){
54221
- return getNameTpl(field, options)
54222
- }
54223
- switch (field.type) {
54224
- case 'password':
54225
- return getPasswordTpl(field);
54226
- case 'boolean':
54227
- return getSwitchTpl(field);
54228
- case 'toggle':
54229
- return getSwitchTpl(field);
54230
- case 'select':
54231
- return getSelectTpl(field);
54232
- case 'time':
54233
- return getTimeTpl(field);
54234
- case 'date':
54235
- return getDateTpl(field);
54236
- case 'datetime':
54237
- return getDateTimeTpl(field);
54238
- case 'lookup':
54239
- return await getRelatedFieldTpl(field, options);
54240
- case 'master_detail':
54241
- return await getRelatedFieldTpl(field, options);
54242
- case 'location':
54243
- return await getLocationTpl(field);
54244
- case 'number':
54245
- case 'currency':
54246
- return await getNumberTpl(field);
54247
- case 'percent':
54248
- case 'formula':
54249
- case 'summary':
54250
- return getUiFieldTpl(field)
54251
- case 'filesize':
54252
- return getUiFileSizeTpl(field)
54253
- }
54254
- }
54255
-
54256
- async function getFieldsTemplate(fields, display){
54257
- let expandFields = [];
54258
- if(display != false){
54259
- display = true;
54260
- }
54261
- let fieldsName = ['_id'];
54262
- let displayFields = [];
54263
- let fieldsArr = [];
54264
- if(lodash.exports.isArray(fields)){
54265
- fieldsArr = fields;
54266
- }else {
54267
- fieldsArr = lodash.exports.values(fields);
54268
- }
54269
- for (const field of fieldsArr) {
54270
- //graphql 的 ui\display 中使用的字段需要先在query中查询. 否则会返回null
54271
- if(field.expand){
54272
- expandFields.push(field);
54273
- }else {
54274
- if(field.name.indexOf('.') < 0){
54275
- if(display && (field.type == 'lookup' || field.type == 'master_detail')){
54276
- fieldsName.push(`${field.name}`);
54277
- displayFields.push(`${field.name}`);
54278
- }else {
54279
- fieldsName.push( field.alias ? `${field.alias}:${field.name}` : field.name);
54280
- }
54281
- if(lodash.exports.includes(['time','date','datetime','boolean','number','currency'], field.type)){
54282
- fieldsName.push(`${field.name}`);
54283
- }
54284
- if(lodash.exports.includes(['percent','time','filesize','date','datetime','boolean','number','currency', 'select', 'file', 'image', 'avatar', 'formula', 'summary', 'object', 'grid'], field.type)){
54285
- displayFields.push(`${field.name}`);
54286
- }
54287
- }else {
54288
- objectFieldName = field.name.split('.')[0];
54289
- fieldsName.push(objectFieldName);
54290
- displayFields.push(objectFieldName);
54291
- }
54292
- }
54293
- }
54294
-
54295
- displayFields = lodash.exports.uniq(displayFields);
54296
- fieldsName = lodash.exports.uniq(fieldsName);
54297
- let expandFieldsQuery = "";
54298
- if(expandFields.length > 0){
54299
- lodash.exports.each(expandFields, function(field){
54300
- expandFieldsQuery = expandFieldsQuery + `${field.expandInfo.fieldName}__expand{${field.expandInfo.displayName}}`;
54301
- });
54302
- }
54303
-
54304
- if(displayFields.length > 0){
54305
- return `${fieldsName.join(',')},${expandFieldsQuery},_display:_ui{${displayFields.join(',')}}`;
54306
- }
54307
- return lodash.exports.trimEnd(`${fieldsName.join(' ')},${expandFieldsQuery}`, ",")
54308
- }
54309
-
54310
- async function getFindQuery(object, recordId, fields, options){
54311
- let limit = options.limit || 10;
54312
- let queryOptions = `(top: ${limit})`;
54313
- if(recordId){
54314
- queryOptions = `(filters:["_id", "=", "${recordId}"], top: ${limit})`;
54315
- }
54316
- let alias = "data";
54317
- if(options){
54318
- if(options.alias){
54319
- alias = options.alias;
54320
- }
54321
-
54322
- if(options.filters){
54323
- queryOptions = `(filters:${options.filters})`;
54324
- }
54325
- if(options.queryOptions){
54326
- queryOptions = `(${options.queryOptions})`;
54327
- }
54328
- }
54329
- var treeFields = '';
54330
- if(object.enable_tree && lodash.exports.includes(lodash.exports.keys(object.fields), 'parent') && lodash.exports.includes(lodash.exports.keys(object.fields), 'children')){
54331
- treeFields = ',parent,children';
54332
- }
54333
-
54334
- var cfsFields = '';
54335
- if(object.name === 'cms_files'){
54336
- cfsFields = ',versions';
54337
- }
54338
-
54339
- const countQuery = options.count === false ? "" : `,count:${object.name}__count(filters:{__filters})`;
54340
- // const moreQuerie = options.moreQueries?.length ? ("," + options.moreQueries.map(function(item){
54341
- // // 把最外层的{}去除
54342
- // return item.replace(/^{/,"").replace(/}$/,"");
54343
- // }).join(",")) : "";
54344
-
54345
- return {
54346
- orderBy: "${orderBy}",
54347
- orderDir: "${orderDir}",
54348
- pageNo: "${page}",
54349
- pageSize: "${perPage}",
54350
- query: `{${alias}:${object.name}${queryOptions}{${await getFieldsTemplate(fields, options.expand)}${treeFields}${cfsFields}}${countQuery}}`
54351
- }
54352
- }
54353
-
54354
- function getApi$2 (isMobile){
54355
- if(isMobile);else {
54356
- // return __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + "/graphql"
54357
- return `\${context.rootUrl}/graphql?reload=\${additionalFilters}`
54358
- }
54073
+ function getApi$2 (isMobile){
54074
+ if(isMobile);else {
54075
+ // return __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + "/graphql"
54076
+ return `\${context.rootUrl}/graphql?reload=\${additionalFilters}`
54077
+ }
54359
54078
  }
54360
54079
 
54361
54080
  var frontend_field_group_generalization$1 = "General";
@@ -54808,6 +54527,67 @@ async function getListSchema$1(fields, options){
54808
54527
  }
54809
54528
  }
54810
54529
 
54530
+ /*
54531
+ * @Author: baozhoutao@steedos.com
54532
+ * @Date: 2022-07-20 16:29:22
54533
+ * @LastEditors: liaodaxue
54534
+ * @LastEditTime: 2023-09-11 17:19:53
54535
+ * @Description:
54536
+ */
54537
+
54538
+ function getImageFieldUrl(url) {
54539
+ if (window.Meteor && window.Meteor.isCordova != true) {
54540
+ // '//'的位置
54541
+ const doubleSlashIndex = url.indexOf('//');
54542
+ const urlIndex = url.indexOf('/', doubleSlashIndex + 2);
54543
+ const rootUrl = url.substring(urlIndex);
54544
+ return rootUrl;
54545
+ }
54546
+ return url;
54547
+ }
54548
+
54549
+ if(typeof window != 'undefined'){
54550
+ window.getImageFieldUrl = getImageFieldUrl;
54551
+ }
54552
+
54553
+ function getContrastColor(bgColor) {
54554
+ var backgroundColor = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor;
54555
+ var r = parseInt(backgroundColor.substr(0, 2), 16);
54556
+ var g = parseInt(backgroundColor.substr(2, 2), 16);
54557
+ var b = parseInt(backgroundColor.substr(4, 2), 16);
54558
+ var brightness = (r * 299 + g * 587 + b * 114) / 1000;
54559
+ return brightness < 128 ? "#ffffff" : "#000000";
54560
+ }
54561
+
54562
+ function getLookupListView(refObjectConfig) {
54563
+ if(!refObjectConfig){
54564
+ return null;
54565
+ }
54566
+ const listNameAll = "all";
54567
+ const listNameLookup = "lookup";
54568
+ let listViewAll, listViewLookup;
54569
+
54570
+ _.each(
54571
+ refObjectConfig.list_views,
54572
+ (view, name) => {
54573
+ if (name === listNameAll) {
54574
+ listViewAll = view;
54575
+ if(!listViewAll.name){
54576
+ listViewAll.name = name;
54577
+ }
54578
+ }
54579
+ else if (name === listNameLookup) {
54580
+ listViewLookup = view;
54581
+ if(!listViewLookup.name){
54582
+ listViewLookup.name = name;
54583
+ }
54584
+ }
54585
+ }
54586
+ );
54587
+ let listView = listViewLookup || listViewAll;
54588
+ return listView;
54589
+ }
54590
+
54811
54591
  /*
54812
54592
  * @Author: baozhoutao@steedos.com
54813
54593
  * @Date: 2022-11-01 15:51:00
@@ -57523,7 +57303,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
57523
57303
  if(refObjectConfig.name === 'organizations'){
57524
57304
  labelFieldName = 'name';
57525
57305
  }
57526
- pickerSchema = await getTableSchema$1(tableFields, {
57306
+ pickerSchema = await getTableSchema(tableFields, {
57527
57307
  labelFieldName,
57528
57308
  top: top,
57529
57309
  isLookup: true,
@@ -58013,7 +57793,7 @@ async function getIdsPickerSchema(field, readonly, ctx){
58013
57793
  actions: false
58014
57794
  });
58015
57795
  }else {
58016
- pickerSchema = await getTableSchema$1(tableFields, {
57796
+ pickerSchema = await getTableSchema(tableFields, {
58017
57797
  labelFieldName: refObjectConfig.NAME_FIELD_KEY,
58018
57798
  top: top,
58019
57799
  isLookup: true,
@@ -58762,295 +58542,907 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
58762
58542
  return value; // 切换到数字之后的默认值
58763
58543
  }
58764
58544
  }
58765
- };
58766
- break;
58767
- case 'avatar':
58768
- convertData = getAmisFileSchema(field, readonly);
58769
- break;
58770
- case 'image':
58771
- convertData = getAmisFileSchema(field, readonly);
58772
- break;
58773
- case 'file':
58774
- convertData = getAmisFileSchema(field, readonly);
58545
+ };
58546
+ break;
58547
+ case 'avatar':
58548
+ convertData = getAmisFileSchema(field, readonly);
58549
+ break;
58550
+ case 'image':
58551
+ convertData = getAmisFileSchema(field, readonly);
58552
+ break;
58553
+ case 'file':
58554
+ convertData = getAmisFileSchema(field, readonly);
58555
+ break;
58556
+ case 'formula':
58557
+ if(readonly){
58558
+ convertData = {
58559
+ type: 'static-tpl',
58560
+ tpl: getUiFieldTpl(field)
58561
+ };
58562
+ }
58563
+ break;
58564
+ case 'summary':
58565
+ if(readonly){
58566
+ convertData = {
58567
+ type: 'static-tpl',
58568
+ tpl: getUiFieldTpl(field)
58569
+ };
58570
+ }
58571
+ break;
58572
+ case 'code':
58573
+ convertData = {
58574
+ type: "editor",
58575
+ disabled: readonly ? true : false,
58576
+ language: field.language,
58577
+ editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
58578
+ };
58579
+ break;
58580
+ case 'toggle':
58581
+ convertData = {
58582
+ type: "switch",
58583
+ name: field.name,
58584
+ label: field.label,
58585
+ width: field.width,
58586
+ toggled: field.toggled,
58587
+ disabled: readonly,
58588
+ };
58589
+ break;
58590
+ case 'grid':
58591
+ if(field.subFields){
58592
+ convertData = {
58593
+ type: 'input-table',
58594
+ showIndex: true,
58595
+ columnsTogglable: false,
58596
+ strictMode:false,
58597
+ affixHeader: false, // 是否固定表头, 不固定表头, 否则form有y轴滚动条时, 表头会跟随滚动条滚动.
58598
+ needConfirm: false,
58599
+ editable: !readonly,
58600
+ addable: !readonly,
58601
+ removable: !readonly,
58602
+ draggable: !readonly,
58603
+ columns: []
58604
+ };
58605
+ // console.log(`convertData ==2====>`, field, convertData)
58606
+ for (const subField of field.subFields) {
58607
+ const subFieldName = subField.name.replace(`${field._prefix || ''}${field.name}.$.`, '').replace(`${field.name}.`, '');
58608
+ const gridSub = await convertSFieldToAmisField(Object.assign({}, subField, {name: subFieldName, isTableField: true}), readonly, ctx);
58609
+ if(gridSub){
58610
+ delete gridSub.name;
58611
+ delete gridSub.label;
58612
+ const gridItemSchema = {
58613
+ name: subFieldName,
58614
+ label: subField.label,
58615
+ quickEdit: readonly ? false : gridSub
58616
+ };
58617
+ if(["lookup", "boolean", "toggle"].indexOf(subField.type) > -1){
58618
+ gridItemSchema.type = gridSub.type;
58619
+ gridItemSchema.tpl = gridSub.tpl;
58620
+ }
58621
+ convertData.columns.push(Object.assign({}, gridItemSchema, subField.amis, {name: subFieldName}));
58622
+ }
58623
+ }
58624
+ }
58775
58625
  break;
58776
- case 'formula':
58777
- if(readonly){
58626
+ case 'object':
58627
+ if(field.subFields){
58778
58628
  convertData = {
58779
- type: 'static-tpl',
58780
- tpl: getUiFieldTpl(field)
58629
+ type: 'combo',
58630
+ items: []
58781
58631
  };
58632
+ // console.log(`convertData ======>`, field, convertData)
58633
+ for (let subField of field.subFields) {
58634
+ let subFieldName = subField.name.replace(`${field.name}.$.`, '').replace(`${field.name}.`, '');
58635
+ if(subField.type === 'grid'){
58636
+ subField = await getGridFieldSubFields(subField, ctx.__formFields);
58637
+ }else {
58638
+ if(readonly){
58639
+ subFieldName = `${field.name}.${subFieldName}`;
58640
+ }
58641
+ }
58642
+ const gridSub = await convertSFieldToAmisField(Object.assign({}, subField, {name: subFieldName}), readonly, ctx);
58643
+ if(gridSub){
58644
+ delete gridSub.name;
58645
+ delete gridSub.label;
58646
+ convertData.items.push(
58647
+ Object.assign({}, gridSub, {label: subField.label}, subField.amis, {
58648
+ name: subFieldName
58649
+ })
58650
+ );
58651
+ }
58652
+ }
58653
+ }
58654
+ break;
58655
+ }
58656
+ if(!lodash.exports.isEmpty(convertData)){
58657
+ if(field.is_wide || convertData.type === 'group'){
58658
+ convertData.className = 'col-span-2 m-1';
58659
+ }else {
58660
+ convertData.className = 'm-1';
58661
+ }
58662
+ if(readonly){
58663
+ convertData.className = `${convertData.className} border-b`;
58664
+ }
58665
+ if(readonly){
58666
+ convertData.quickEdit = false;
58667
+ }
58668
+
58669
+ let fieldTypeClassName = ' steedos-' + convertData.type + (readonly ? '-readonly' : '-edit');
58670
+ if (convertData.className) {
58671
+ convertData.className = convertData.className + fieldTypeClassName;
58672
+ } else {
58673
+ convertData.className = fieldTypeClassName;
58674
+ }
58675
+
58676
+ if(field.visible_on && !ctx.inFilterForm){
58677
+ // convertData.visibleOn = `\$${field.visible_on.substring(1, field.visible_on.length -1).replace(/formData./g, '')}`;
58678
+ if(field.visible_on.startsWith("{{")){
58679
+ convertData.visibleOn = `${field.visible_on.substring(2, field.visible_on.length -2).replace(/formData./g, 'data.')}`;
58680
+ }else {
58681
+ convertData.visibleOn = `${field.visible_on.replace(/formData./g, 'data.')}`;
58682
+ }
58683
+ }
58684
+
58685
+ if(lodash.exports.isString(baseData.required)){
58686
+ if(baseData.required.startsWith("{{")){
58687
+ baseData.requiredOn = `${baseData.required.substring(2, baseData.required.length -2).replace(/formData./g, 'data.')}`;
58688
+ delete baseData.required;
58689
+ }
58690
+ }
58691
+
58692
+ if(convertData.type === 'group'){
58693
+ convertData.body[0] = Object.assign({}, baseData, convertData.body[0], { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name});
58694
+ return convertData
58695
+ }
58696
+ // if(ctx.mode === 'edit'){
58697
+ return Object.assign({}, baseData, convertData, { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name}, field.amis, {name: baseData.name});
58698
+ // }else{
58699
+ // return Object.assign({}, baseData, convertData, { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name});
58700
+ // }
58701
+ }
58702
+
58703
+ }
58704
+
58705
+ async function getFieldSearchable(perField, permissionFields, ctx){
58706
+ if(!ctx){
58707
+ ctx = {};
58708
+ }
58709
+ let field = perField;
58710
+ if(field.type === 'grid'){
58711
+ field = await getGridFieldSubFields(perField, permissionFields);
58712
+ }else if(perField.type === 'object'){
58713
+ field = await getObjectFieldSubFields(perField, permissionFields);
58714
+ }
58715
+
58716
+ let fieldNamePrefix = '__searchable__';
58717
+ if(field.name.indexOf(".") < 0){
58718
+ let _field = lodash.exports.cloneDeep(field);
58719
+ if(lodash.exports.includes(['textarea', 'html', 'code', 'autonumber'], field.type)){
58720
+ _field.type = 'text';
58721
+ }
58722
+
58723
+ if(lodash.exports.includes(['formula', 'summary'], field.type)){
58724
+ _field.type = field.data_type;
58725
+ _field.precision = field.precision;
58726
+ _field.scale = field.scale;
58727
+ }
58728
+ else if(field.type === "select" && field.data_type && field.data_type != "text"){
58729
+ _field.type = field.data_type;
58730
+ }
58731
+
58732
+ if(_field.type === 'number' || _field.type === 'currency'){
58733
+ _field.type = 'input-array';
58734
+ _field.inline = true;
58735
+ _field.addable = false;
58736
+ _field.removable = false;
58737
+ _field.value = [null,null];
58738
+ _field.items = {
58739
+ type: "input-number"
58740
+ };
58741
+ _field.is_wide = true;
58742
+ fieldNamePrefix = `${fieldNamePrefix}between__`;
58743
+ }
58744
+
58745
+ if(_field.type ==='date'){
58746
+ _field.type = 'input-date-range';
58747
+ _field.is_wide = true;
58748
+ fieldNamePrefix = `${fieldNamePrefix}between__`;
58749
+ }
58750
+ if(_field.type === 'datetime'){
58751
+ _field.type = 'input-datetime-range';
58752
+ _field.is_wide = true;
58753
+ fieldNamePrefix = `${fieldNamePrefix}between__`;
58754
+ }
58755
+ if(_field.type === 'time'){
58756
+ _field.type = 'input-time-range';
58757
+ _field.is_wide = true;
58758
+ fieldNamePrefix = `${fieldNamePrefix}between__`;
58759
+ }
58760
+ if(_field.reference_to === 'users'){
58761
+ _field.reference_to = 'space_users';
58762
+ _field.reference_to_field = 'user';
58763
+ }
58764
+ _field.readonly = false;
58765
+ _field.disabled = false;
58766
+ _field.multiple = true;
58767
+ _field.is_wide = false;
58768
+ _field.defaultValue = undefined;
58769
+ _field.required = false;
58770
+ _field.hidden = false;
58771
+ _field.omit = false;
58772
+
58773
+ if(_field.amis){
58774
+ delete _field.amis.static;
58775
+ delete _field.amis.staticOn;
58776
+ delete _field.amis.disabled;
58777
+ delete _field.amis.disabledOn;
58778
+ delete _field.amis.required;
58779
+ delete _field.amis.requiredOn;
58780
+ delete _field.amis.visible;
58781
+ delete _field.amis.visibleOn;
58782
+ delete _field.amis.hidden;
58783
+ delete _field.amis.hiddenOn;
58784
+ delete _field.amis.autoFill;
58785
+ }
58786
+
58787
+ const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true, inFilterForm: true}));
58788
+ if(amisField){
58789
+ return Object.assign({}, amisField,{
58790
+ submitOnChange: true
58791
+ });
58792
+ }
58793
+ }
58794
+ }
58795
+
58796
+ if(typeof window != 'undefined'){
58797
+ window.getFieldSearchable = getFieldSearchable;
58798
+ }
58799
+
58800
+
58801
+ function isFieldTypeSearchable(fieldType) {
58802
+ return !lodash.exports.includes(
58803
+ [
58804
+ "grid",
58805
+ "avatar",
58806
+ "image",
58807
+ "object",
58808
+ "[object]",
58809
+ "[Object]",
58810
+ "[grid]",
58811
+ "[text]",
58812
+ "audio",
58813
+ "file",
58814
+ ],
58815
+ fieldType
58816
+ )
58817
+ }
58818
+
58819
+ if (typeof window != 'undefined') {
58820
+ window.isFieldTypeSearchable = isFieldTypeSearchable;
58821
+ }
58822
+
58823
+
58824
+ function isFieldQuickSearchable(field, nameFieldKey) {
58825
+ let fieldSearchable = field.searchable;
58826
+ if(fieldSearchable !== false && field.name === nameFieldKey){
58827
+ // 对象上名称字段的searchable默认认为是true
58828
+ fieldSearchable = true;
58829
+ }
58830
+ if (fieldSearchable && QUICK_SEARCHABLE_FIELD_TYPES.indexOf(field.type) > -1) {
58831
+ return true;
58832
+ }
58833
+ return false;
58834
+ }
58835
+
58836
+ /******************************************************************************
58837
+ Copyright (c) Microsoft Corporation.
58838
+
58839
+ Permission to use, copy, modify, and/or distribute this software for any
58840
+ purpose with or without fee is hereby granted.
58841
+
58842
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
58843
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
58844
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
58845
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
58846
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
58847
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
58848
+ PERFORMANCE OF THIS SOFTWARE.
58849
+ ***************************************************************************** */
58850
+
58851
+ var __assign = function() {
58852
+ __assign = Object.assign || function __assign(t) {
58853
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
58854
+ s = arguments[i];
58855
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
58856
+ }
58857
+ return t;
58858
+ };
58859
+ return __assign.apply(this, arguments);
58860
+ };
58861
+
58862
+ // 方便取值的时候能够把上层的取到,但是获取的时候不会全部把所有的数据获取到。
58863
+ function createObject(superProps, props, properties) {
58864
+ if (superProps && Object.isFrozen(superProps)) {
58865
+ superProps = cloneObject(superProps);
58866
+ }
58867
+ var obj = superProps
58868
+ ? Object.create(superProps, __assign(__assign({}, properties), { __super: {
58869
+ value: superProps,
58870
+ writable: false,
58871
+ enumerable: false
58872
+ } }))
58873
+ : Object.create(Object.prototype, properties);
58874
+ props &&
58875
+ isObject(props) &&
58876
+ Object.keys(props).forEach(function (key) { return (obj[key] = props[key]); });
58877
+ return obj;
58878
+ }
58879
+ function cloneObject(target, persistOwnProps) {
58880
+ if (persistOwnProps === void 0) { persistOwnProps = true; }
58881
+ var obj = target && target.__super
58882
+ ? Object.create(target.__super, {
58883
+ __super: {
58884
+ value: target.__super,
58885
+ writable: false,
58886
+ enumerable: false
58782
58887
  }
58783
- break;
58784
- case 'summary':
58785
- if(readonly){
58786
- convertData = {
58787
- type: 'static-tpl',
58788
- tpl: getUiFieldTpl(field)
58789
- };
58888
+ })
58889
+ : Object.create(Object.prototype);
58890
+ persistOwnProps &&
58891
+ target &&
58892
+ Object.keys(target).forEach(function (key) { return (obj[key] = target[key]); });
58893
+ return obj;
58894
+ }
58895
+ function isObject(obj) {
58896
+ var typename = typeof obj;
58897
+ return (obj &&
58898
+ typename !== 'string' &&
58899
+ typename !== 'number' &&
58900
+ typename !== 'boolean' &&
58901
+ typename !== 'function' &&
58902
+ !Array.isArray(obj));
58903
+ }
58904
+
58905
+ /*
58906
+ * @Author: baozhoutao@steedos.com
58907
+ * @Date: 2022-07-05 15:55:39
58908
+ * @LastEditors: liaodaxue
58909
+ * @LastEditTime: 2023-10-20 11:38:25
58910
+ * @Description:
58911
+ */
58912
+
58913
+ let UI_SCHEMA_CACHE = {};
58914
+
58915
+ let UISchemaFunction;
58916
+
58917
+ if('undefined' != typeof window){
58918
+ if(!window.UI_SCHEMA_CACHE){
58919
+ window.UI_SCHEMA_CACHE = UI_SCHEMA_CACHE;
58920
+ }
58921
+ UI_SCHEMA_CACHE = window.UI_SCHEMA_CACHE;
58922
+ }
58923
+
58924
+ const setUISchemaCache = (key, value) => {
58925
+ UI_SCHEMA_CACHE[key] = value;
58926
+ };
58927
+
58928
+ const getUISchemaCache = (key) => {
58929
+ return lodash.exports.cloneDeep(UI_SCHEMA_CACHE[key]);
58930
+ };
58931
+
58932
+ const hasUISchemaCache = (key) => {
58933
+ return lodash.exports.has(UI_SCHEMA_CACHE, key);
58934
+ };
58935
+
58936
+ function getListViewColumns(listView, formFactor) {
58937
+ let listViewColumns = [];
58938
+ if (formFactor === "SMALL") {
58939
+ listViewColumns = !lodash.exports.isEmpty(listView.mobile_columns)
58940
+ ? listView.mobile_columns
58941
+ : lodash.exports.slice(listView.columns, 0, 4);
58942
+ } else {
58943
+ listViewColumns = listView.columns;
58944
+ }
58945
+ return listViewColumns;
58946
+ }
58947
+ function getListViewSort(listView) {
58948
+ let sort = '';
58949
+ if(listView && listView.sort && listView.sort.length){
58950
+ lodash.exports.each(listView.sort,function(item,index){
58951
+ if(lodash.exports.isArray(item)){
58952
+ const field_name = item[0];
58953
+ const order = item[1] || '';
58954
+ let sortStr = field_name + ' ' + order;
58955
+ sortStr = index > 0 ? ','+sortStr : sortStr;
58956
+ sort += sortStr;
58957
+ }else {
58958
+ let sortStr = item.field_name + ' ' + item.order;
58959
+ sortStr = index > 0 ? ','+sortStr : sortStr;
58960
+ sort += sortStr;
58790
58961
  }
58791
- break;
58792
- case 'code':
58793
- convertData = {
58794
- type: "editor",
58795
- disabled: readonly ? true : false,
58796
- language: field.language,
58797
- editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
58798
- };
58799
- break;
58800
- case 'toggle':
58801
- convertData = {
58802
- type: "switch",
58803
- name: field.name,
58804
- label: field.label,
58805
- width: field.width,
58806
- toggled: field.toggled,
58807
- disabled: readonly,
58808
- };
58809
- break;
58810
- case 'grid':
58811
- if(field.subFields){
58812
- convertData = {
58813
- type: 'input-table',
58814
- showIndex: true,
58815
- columnsTogglable: false,
58816
- strictMode:false,
58817
- affixHeader: false, // 是否固定表头, 不固定表头, 否则form有y轴滚动条时, 表头会跟随滚动条滚动.
58818
- needConfirm: false,
58819
- editable: !readonly,
58820
- addable: !readonly,
58821
- removable: !readonly,
58822
- draggable: !readonly,
58823
- columns: []
58824
- };
58825
- // console.log(`convertData ==2====>`, field, convertData)
58826
- for (const subField of field.subFields) {
58827
- const subFieldName = subField.name.replace(`${field._prefix || ''}${field.name}.$.`, '').replace(`${field.name}.`, '');
58828
- const gridSub = await convertSFieldToAmisField(Object.assign({}, subField, {name: subFieldName, isTableField: true}), readonly, ctx);
58829
- if(gridSub){
58830
- delete gridSub.name;
58831
- delete gridSub.label;
58832
- const gridItemSchema = {
58833
- name: subFieldName,
58834
- label: subField.label,
58835
- quickEdit: readonly ? false : gridSub
58836
- };
58837
- if(["lookup", "boolean", "toggle"].indexOf(subField.type) > -1){
58838
- gridItemSchema.type = gridSub.type;
58839
- gridItemSchema.tpl = gridSub.tpl;
58840
- }
58841
- convertData.columns.push(Object.assign({}, gridItemSchema, subField.amis, {name: subFieldName}));
58842
- }
58962
+ });
58963
+ }
58964
+ return sort;
58965
+ }
58966
+ function getListViewFilter(listView){
58967
+ if(!listView){
58968
+ return ;
58969
+ }
58970
+ try {
58971
+ const userId = getUserId();
58972
+ let filters = listView.filters;
58973
+ if(listView.filter_scope === 'mine'){
58974
+ if(___default.isEmpty(filters)){
58975
+ filters = [["owner", "=", userId]];
58976
+ }else {
58977
+ if(___default.isString(filters) && ___default.startsWith(___default.trim(filters), "function")){
58978
+ filters = new Function(`return ${filters}`);
58979
+ filters = filters();
58843
58980
  }
58844
- }
58845
- break;
58846
- case 'object':
58847
- if(field.subFields){
58848
- convertData = {
58849
- type: 'combo',
58850
- items: []
58851
- };
58852
- // console.log(`convertData ======>`, field, convertData)
58853
- for (let subField of field.subFields) {
58854
- let subFieldName = subField.name.replace(`${field.name}.$.`, '').replace(`${field.name}.`, '');
58855
- if(subField.type === 'grid'){
58856
- subField = await getGridFieldSubFields(subField, ctx.__formFields);
58857
- }else {
58858
- if(readonly){
58859
- subFieldName = `${field.name}.${subFieldName}`;
58860
- }
58861
- }
58862
- const gridSub = await convertSFieldToAmisField(Object.assign({}, subField, {name: subFieldName}), readonly, ctx);
58863
- if(gridSub){
58864
- delete gridSub.name;
58865
- delete gridSub.label;
58866
- convertData.items.push(
58867
- Object.assign({}, gridSub, {label: subField.label}, subField.amis, {
58868
- name: subFieldName
58869
- })
58870
- );
58871
- }
58981
+ if(___default.isArray(filters)){
58982
+ filters.push(["owner", "=", userId]);
58983
+ }else {
58984
+ console.debug(`listView filters is not array`, listView);
58985
+ throw new Error('filters is not array')
58872
58986
  }
58873
58987
  }
58874
- break;
58988
+ };
58989
+ return filters;
58990
+ } catch (error) {
58991
+ console.error(error);
58992
+ }
58993
+ }
58994
+
58995
+ function formatUISchemaCache(objectName, uiSchema){
58996
+ setUISchemaCache(objectName, uiSchema);
58997
+ lodash.exports.each(uiSchema.fields, (field)=>{
58998
+ try {
58999
+ if(field.type === "lookup" && field._reference_to && ___default.isString(field._reference_to)){
59000
+ field.reference_to = eval(`(${field._reference_to})`)();
59001
+ }
59002
+ } catch (exception) {
59003
+ field.reference_to = undefined;
59004
+ console.error(exception);
59005
+ }
59006
+ });
59007
+ lodash.exports.each(uiSchema.list_views, (v, k)=>{
59008
+ v.name = k;
59009
+ if(!lodash.exports.has(v, 'columns')){
59010
+ v.columns = uiSchema.list_views.all.columns;
59011
+ }
59012
+ });
59013
+ }
59014
+
59015
+ async function getUISchema(objectName, force) {
59016
+ if (!objectName) {
59017
+ return;
59018
+ }
59019
+ if (hasUISchemaCache(objectName) && !force) {
59020
+ return getUISchemaCache(objectName);
59021
+ }
59022
+ let uiSchema = null;
59023
+ try {
59024
+ if(UISchemaFunction);
59025
+ else {
59026
+ const url = `/service/api/@${objectName.replace(/\./g, "_")}/uiSchema`;
59027
+ uiSchema = await fetchAPI(url, { method: "get" });
59028
+ }
59029
+ if(!uiSchema){
59030
+ return ;
59031
+ }
59032
+ formatUISchemaCache(objectName, uiSchema);
59033
+ } catch (error) {
59034
+ console.error(`getUISchema`, objectName, error);
59035
+ setUISchemaCache(objectName, null);
59036
+ }
59037
+ return getUISchemaCache(objectName);
59038
+ }
59039
+
59040
+ function getUISchemaSync(objectName, force) {
59041
+ if (!objectName) {
59042
+ return;
58875
59043
  }
58876
- if(!lodash.exports.isEmpty(convertData)){
58877
- if(field.is_wide || convertData.type === 'group'){
58878
- convertData.className = 'col-span-2 m-1';
58879
- }else {
58880
- convertData.className = 'm-1';
58881
- }
58882
- if(readonly){
58883
- convertData.className = `${convertData.className} border-b`;
59044
+ if (hasUISchemaCache(objectName) && !force) {
59045
+ return getUISchemaCache(objectName);
59046
+ }
59047
+ let uiSchema = null;
59048
+ try {
59049
+
59050
+ const url = `/service/api/@${objectName.replace(/\./g, "_")}/uiSchema`;
59051
+ uiSchema = Steedos.authRequest(url, {
59052
+ type: 'GET',
59053
+ async: false,
59054
+ });
59055
+
59056
+ if(!uiSchema){
59057
+ return ;
58884
59058
  }
58885
- if(readonly){
58886
- convertData.quickEdit = false;
59059
+ formatUISchemaCache(objectName, uiSchema);
59060
+ } catch (error) {
59061
+ console.error(`getUISchema`, objectName, error);
59062
+ setUISchemaCache(objectName, null);
59063
+ }
59064
+ return getUISchemaCache(objectName);
59065
+ }
59066
+
59067
+ // 获取列表视图
59068
+ async function getListSchema(
59069
+ appName,
59070
+ objectName,
59071
+ listViewName,
59072
+ ctx = {}
59073
+ ) {
59074
+ const uiSchema = await getUISchema(objectName);
59075
+ if(!uiSchema){
59076
+ return {}
59077
+ }
59078
+ const listView = lodash.exports.find(
59079
+ uiSchema.list_views,
59080
+ (listView, name) => {
59081
+ // 传入listViewName空值则取第一个
59082
+ if(!listViewName){
59083
+ listViewName = name;
59084
+ }
59085
+ return name === listViewName || listView._id === listViewName;
58887
59086
  }
59087
+ );
58888
59088
 
58889
- let fieldTypeClassName = ' steedos-' + convertData.type + (readonly ? '-readonly' : '-edit');
58890
- if (convertData.className) {
58891
- convertData.className = convertData.className + fieldTypeClassName;
58892
- } else {
58893
- convertData.className = fieldTypeClassName;
59089
+ if (!listView) {
59090
+ return { uiSchema };
59091
+ }
59092
+
59093
+ // 直接返回自定义的列表视图schema
59094
+ if(listView.enable_amis_schema && listView.amis_schema){
59095
+ const amisSchema = lodash.exports.isString(listView.amis_schema) ? JSON.parse(listView.amis_schema) : listView.amis_schema;
59096
+ return {
59097
+ uiSchema,
59098
+ isCustomAmisSchema: true,
59099
+ amisSchema
59100
+ };
59101
+ }
59102
+
59103
+ let listViewColumns = getListViewColumns(listView, ctx.formFactor);
59104
+ let sort = getListViewSort(listView);
59105
+ let listviewFilter = getListViewFilter(listView);
59106
+ let listview_filters = listView && listView._filters;
59107
+ // 返回 calendar 组件
59108
+ if(listView.type === "calendar"){
59109
+ const amisSchema = {
59110
+ "type": "steedos-object-calendar",
59111
+ "objectApiName": objectName,
59112
+ "filters": listviewFilter,
59113
+ "filtersFunction": listview_filters,
59114
+ "sort": sort,
59115
+ ...listView.options
59116
+ };
59117
+ return {
59118
+ uiSchema,
59119
+ isCalendar: true,
59120
+ amisSchema
59121
+ };
59122
+ }
59123
+
59124
+ const defaults = ctx.defaults || {};
59125
+
59126
+ // // 未自定义header 且显示header的时候, 使用系统header
59127
+ // if(!defaults.headerSchema && ctx.showHeader){
59128
+ // defaults.headerSchema = getObjectListHeader(uiSchema, listViewName);
59129
+ // }
59130
+
59131
+ // // 如果不显示header,则清理掉
59132
+ // if(!ctx.showHeader){
59133
+ // defaults.headerSchema = null;
59134
+ // }
59135
+
59136
+ defaults.headerSchema = null;
59137
+
59138
+ /**
59139
+ * 本次存储代码段
59140
+ */
59141
+ try {
59142
+ const listViewPropsStoreKey = location.pathname + "/crud";
59143
+ let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
59144
+ /**
59145
+ * localListViewProps规范来自crud请求api中api.data.$self参数值的。
59146
+ * 比如:{"perPage":20,"page":1,"__searchable__name":"7","__searchable__between__n1__c":[null,null],"filter":[["name","contains","a"]]}
59147
+ * __searchable__...:顶部放大镜搜索条件
59148
+ * filter:右侧过滤器
59149
+ * perPage:每页条数
59150
+ * page:当前页码
59151
+ * orderBy:排序字段
59152
+ * orderDir:排序方向
59153
+ */
59154
+ if (localListViewProps) {
59155
+ localListViewProps = JSON.parse(localListViewProps);
59156
+ // localListViewProps.perPage = 3;
59157
+ let listSchema = {};
59158
+ if(localListViewProps.orderBy){
59159
+ listSchema.orderBy = localListViewProps.orderBy;
59160
+ }
59161
+ if(localListViewProps.orderDir){
59162
+ listSchema.orderDir = localListViewProps.orderDir;
58894
59163
  }
58895
59164
 
58896
- if(field.visible_on && !ctx.inFilterForm){
58897
- // convertData.visibleOn = `\$${field.visible_on.substring(1, field.visible_on.length -1).replace(/formData./g, '')}`;
58898
- if(field.visible_on.startsWith("{{")){
58899
- convertData.visibleOn = `${field.visible_on.substring(2, field.visible_on.length -2).replace(/formData./g, 'data.')}`;
58900
- }else {
58901
- convertData.visibleOn = `${field.visible_on.replace(/formData./g, 'data.')}`;
58902
- }
59165
+ if(localListViewProps.perPage){
59166
+ listSchema.defaultParams = {
59167
+ perPage: localListViewProps.perPage
59168
+ };
58903
59169
  }
59170
+ defaults.listSchema = lodash.exports.defaultsDeep({}, listSchema, defaults.listSchema || {});
59171
+ }
59172
+ }
59173
+ catch (ex) {
59174
+ console.error("本地存储中crud参数解析异常:", ex);
59175
+ }
58904
59176
 
58905
- if(lodash.exports.isString(baseData.required)){
58906
- if(baseData.required.startsWith("{{")){
58907
- baseData.requiredOn = `${baseData.required.substring(2, baseData.required.length -2).replace(/formData./g, 'data.')}`;
58908
- delete baseData.required;
59177
+ ctx.defaults = defaults;
59178
+
59179
+ if (listViewName == "recent") {
59180
+ listview_filters = `
59181
+ function(filters, data) {
59182
+ var result = Steedos.authRequest('/graphql', {
59183
+ type: 'POST',
59184
+ async: false,
59185
+ data: JSON.stringify({
59186
+ query: '{object_recent_viewed(filters: [["record.o","=","' + data.objectName + '"],["space","=","' + data.context.tenantId + '"],["owner","=","' + data.context.userId + '"]],sort:"modified desc",top:50){ _id,record} }'
59187
+ }),
59188
+ });
59189
+ var _ids = []
59190
+ result.data.object_recent_viewed.forEach(function (item) {
59191
+ _ids = _ids.concat(item.record.ids)
59192
+ })
59193
+ return ["_id", "=", _ids];
58909
59194
  }
58910
- }
59195
+ `;
59196
+ }
59197
+ const amisSchema = {
59198
+ "type": "steedos-object-table",
59199
+ "objectApiName": objectName,
59200
+ "columns": listViewColumns,
59201
+ "extraColumns": listView.extra_columns,
59202
+ "filters": listviewFilter,
59203
+ "filtersFunction": listview_filters,
59204
+ "sort": sort,
59205
+ "ctx": ctx,
59206
+ "requestAdaptor": listView.requestAdaptor || ctx.requestAdaptor,
59207
+ "adaptor": listView.adaptor || ctx.adaptor,
59208
+ "headerToolbarItems": ctx.headerToolbarItems,
59209
+ "filterVisible": ctx.filterVisible,
59210
+ "rowClassNameExpr": ctx.rowClassNameExpr,
59211
+ "crudDataFilter": ctx.crudDataFilter,
59212
+ "onCrudDataFilter": ctx.onCrudDataFilter
59213
+ };
59214
+ // console.log(`getListSchema===>`,amisSchema)
59215
+ return {
59216
+ uiSchema,
59217
+ amisSchema,
59218
+ };
59219
+ }
58911
59220
 
58912
- if(convertData.type === 'group'){
58913
- convertData.body[0] = Object.assign({}, baseData, convertData.body[0], { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name});
58914
- return convertData
59221
+
59222
+ if(typeof window != 'undefined'){
59223
+ window.getUISchema = getUISchema;
59224
+ window.getUISchemaSync = getUISchemaSync;
59225
+ window.getListSchema = getListSchema;
59226
+ }
59227
+
59228
+ function getNumberTpl(field){
59229
+ return `<span>\${_display.${field.name}}</span>`
59230
+ }
59231
+
59232
+ function getTimeTpl(field){
59233
+ return `<span>\${_display.${field.name}}</span>`
59234
+ }
59235
+
59236
+ function getDateTpl(field){
59237
+ return `<span>\${_display.${field.name}}</span>`
59238
+ }
59239
+
59240
+
59241
+ function getDateTimeTpl(field){
59242
+ return `<span>\${_display.${field.name}}</span>`
59243
+ }
59244
+
59245
+ function getUiFieldTpl(field){
59246
+ return `<span>\${_display.${field.name}}</span>`
59247
+ }
59248
+
59249
+ function getUiFileSizeTpl(field){
59250
+ return `<span>\${_display.${field.name}}</span>`
59251
+ }
59252
+
59253
+ //TODO 处理name字段
59254
+ async function getRefObjectNameFieldName(field){
59255
+ const refUiSchema = await getUISchema(field.reference_to);
59256
+ const NAME_FIELD_KEY = refUiSchema.NAME_FIELD_KEY || 'name';
59257
+ return NAME_FIELD_KEY;
59258
+ }
59259
+
59260
+ function getSelectTpl(field){
59261
+ return `<span>\${_display.${field.name}}</span>`
59262
+ }
59263
+ function getSelectMap(selectOptions){
59264
+ let map = {};
59265
+ lodash.exports.forEach(selectOptions,(option)=>{
59266
+ const optionValue = option.value + '';
59267
+ const optionColor = option.color + '';
59268
+ if(optionColor){
59269
+ const background = optionColor.charAt(0) === '#' ? optionColor : '#'+optionColor;
59270
+ const color = getContrastColor(background);
59271
+ const optionColorStyle = 'background:'+background+';color:'+color+';line-height:1.5rem';
59272
+ map[optionValue] = `<span class="rounded-xl px-2 py-1" style='${optionColorStyle}'>${option.label}</span>`;
59273
+ }else {
59274
+ map[optionValue] = option.label;
58915
59275
  }
58916
- // if(ctx.mode === 'edit'){
58917
- return Object.assign({}, baseData, convertData, { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name}, field.amis, {name: baseData.name});
58918
- // }else{
58919
- // return Object.assign({}, baseData, convertData, { labelClassName: 'text-left', clearValueOnHidden: true, fieldName: field.name});
58920
- // }
58921
- }
58922
-
59276
+ });
59277
+ return map;
58923
59278
  }
58924
59279
 
58925
- async function getFieldSearchable(perField, permissionFields, ctx){
58926
- if(!ctx){
58927
- ctx = {};
59280
+ function getNameTplUrl(field, ctx){
59281
+ if(ctx.objectName === 'cms_files'){
59282
+ return `\${context.rootUrl}/api/files/files/\${versions[0]}?download=true`
58928
59283
  }
58929
- let field = perField;
58930
- if(field.type === 'grid'){
58931
- field = await getGridFieldSubFields(perField, permissionFields);
58932
- }else if(perField.type === 'object'){
58933
- field = await getObjectFieldSubFields(perField, permissionFields);
59284
+ const href = Router.getObjectDetailPath({
59285
+ ...ctx, formFactor: ctx.formFactor, appId: "${appId}", objectName: ctx.objectName || "${objectName}", recordId: `\${${ctx.idFieldName}}`
59286
+ });
59287
+ return href;
59288
+ }
59289
+
59290
+ function getNameTpl(field, ctx){
59291
+ const href = getNameTplUrl(field, ctx);
59292
+ let linkTarget = "";
59293
+ if(ctx && ctx.isLookup){
59294
+ linkTarget = "target='_blank'";
58934
59295
  }
59296
+ return `<a href="${href}" ${linkTarget}>\${${field.name}}</a>`
59297
+ }
58935
59298
 
58936
- let fieldNamePrefix = '__searchable__';
58937
- if(field.name.indexOf(".") < 0){
58938
- let _field = lodash.exports.cloneDeep(field);
58939
- if(lodash.exports.includes(['textarea', 'html', 'code', 'autonumber'], field.type)){
58940
- _field.type = 'text';
59299
+ function getRelatedFieldTpl(field, ctx){
59300
+ let tpl = '';
59301
+ if(!field.reference_to && (field.optionsFunction || field._optionsFunction || field.options)){
59302
+ if(field.isTableField){
59303
+ return `\${${field.name}}`
59304
+ }else {
59305
+ return `\${${field.name}__label}`
58941
59306
  }
59307
+ }
58942
59308
 
58943
- if(lodash.exports.includes(['formula', 'summary'], field.type)){
58944
- _field.type = field.data_type;
58945
- _field.precision = field.precision;
58946
- _field.scale = field.scale;
58947
- }
58948
- else if(field.type === "select" && field.data_type && field.data_type != "text"){
58949
- _field.type = field.data_type;
58950
- }
59309
+ let linkTarget = "";
59310
+ if(ctx && ctx.isLookup){
59311
+ linkTarget = "target='_blank'";
59312
+ }
58951
59313
 
58952
- if(_field.type === 'number' || _field.type === 'currency'){
58953
- _field.type = 'input-array';
58954
- _field.inline = true;
58955
- _field.addable = false;
58956
- _field.removable = false;
58957
- _field.value = [null,null];
58958
- _field.items = {
58959
- type: "input-number"
58960
- };
58961
- _field.is_wide = true;
58962
- fieldNamePrefix = `${fieldNamePrefix}between__`;
58963
- }
59314
+ const onlyDisplayLookLabel = ctx.onlyDisplayLookLabel;
58964
59315
 
58965
- if(_field.type ==='date'){
58966
- _field.type = 'input-date-range';
58967
- _field.is_wide = true;
58968
- fieldNamePrefix = `${fieldNamePrefix}between__`;
58969
- }
58970
- if(_field.type === 'datetime'){
58971
- _field.type = 'input-datetime-range';
58972
- _field.is_wide = true;
58973
- fieldNamePrefix = `${fieldNamePrefix}between__`;
58974
- }
58975
- if(_field.type === 'time'){
58976
- _field.type = 'input-time-range';
58977
- _field.is_wide = true;
58978
- fieldNamePrefix = `${fieldNamePrefix}between__`;
58979
- }
58980
- if(_field.reference_to === 'users'){
58981
- _field.reference_to = 'space_users';
58982
- _field.reference_to_field = 'user';
58983
- }
58984
- _field.readonly = false;
58985
- _field.disabled = false;
58986
- _field.multiple = true;
58987
- _field.is_wide = false;
58988
- _field.defaultValue = undefined;
58989
- _field.required = false;
58990
- _field.hidden = false;
58991
- _field.omit = false;
59316
+ let fieldDataStrTpl = `data._display.${field.name}`;
58992
59317
 
58993
- if(_field.amis){
58994
- delete _field.amis.static;
58995
- delete _field.amis.staticOn;
58996
- delete _field.amis.disabled;
58997
- delete _field.amis.disabledOn;
58998
- delete _field.amis.required;
58999
- delete _field.amis.requiredOn;
59000
- delete _field.amis.visible;
59001
- delete _field.amis.visibleOn;
59002
- delete _field.amis.hidden;
59003
- delete _field.amis.hiddenOn;
59004
- delete _field.amis.autoFill;
59318
+ if(field.isTableField){
59319
+ fieldDataStrTpl = `data.${field.name}`;
59320
+ }
59321
+
59322
+ if(_.isString(field.reference_to) || !field.reference_to){
59323
+ if(field.multiple){
59324
+ let labelTpl = `<%=item.label%>`;
59325
+ if(!onlyDisplayLookLabel){
59326
+ const href = Router.getObjectDetailPath({
59327
+ formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
59328
+ });
59329
+ labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
59330
+ }
59331
+ tpl = `
59332
+ <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item,index) { %> <% if(index>0 && index<${fieldDataStrTpl}.length){ %> , <% } %> ${labelTpl} <% }); %><% } %>
59333
+ `;
59334
+ }else {
59335
+ let labelTpl = `\${_display.${field.name}.label}`;
59336
+ let objectNameTpl = `\${_display.${field.name}.objectName}`;
59337
+ let recordIdTpl = `\${_display.${field.name}.value}`;
59338
+ if(field.isTableField){
59339
+ labelTpl = `\${${field.name}.label}`;
59340
+ objectNameTpl = `\${${field.name}.objectName}`;
59341
+ recordIdTpl = `\${${field.name}.value}`;
59342
+ }
59343
+ if(!onlyDisplayLookLabel){
59344
+ const href = Router.getObjectDetailPath({
59345
+ formFactor: ctx.formFactor, appId: "${appId}", objectName: `${objectNameTpl}`, recordId: `${recordIdTpl}`
59346
+ });
59347
+ labelTpl = `<a href="${href}" ${linkTarget}>${labelTpl}</a>`;
59348
+ }
59349
+ tpl = labelTpl;
59005
59350
  }
59006
59351
 
59007
- const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true, inFilterForm: true}));
59008
- if(amisField){
59009
- return Object.assign({}, amisField,{
59010
- submitOnChange: true
59352
+
59353
+ }else {
59354
+ let labelTpl = `<%=item.label%>`;
59355
+ if(!onlyDisplayLookLabel){
59356
+ const href = Router.getObjectDetailPath({
59357
+ formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
59011
59358
  });
59359
+ labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
59012
59360
  }
59361
+ tpl = `
59362
+ <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item) { %> ${labelTpl} <% }); %><% } %>
59363
+ `;
59013
59364
  }
59365
+ return tpl
59014
59366
  }
59015
59367
 
59016
- if(typeof window != 'undefined'){
59017
- window.getFieldSearchable = getFieldSearchable;
59368
+ async function getLookupTpl(field, ctx){
59369
+ if(!field.reference_to){
59370
+ return getSelectTpl(field)
59371
+ }
59372
+ const NAME_FIELD_KEY = await getRefObjectNameFieldName(field);
59373
+ if(field.multiple){
59374
+ const href = Router.getObjectDetailPath({
59375
+ formFactor: ctx.formFactor, appId: ctx.appId, objectName: field.reference_to, recordId: `<%=item._id%>`, _templateType: "JavaScript"
59376
+ });
59377
+ return `
59378
+ <% if (data.${field.name} && data.${field.name}.length) { %><% data.${field.name}.forEach(function(item) { %> <a href="${href}"><%=item.${NAME_FIELD_KEY}%></a> <% }); %><% } %>
59379
+ `
59380
+ }else {
59381
+ const href = Router.getObjectDetailPath({
59382
+ formFactor: ctx.formFactor, appId: ctx.appId, objectName: field.reference_to, recordId: `\${${field.name}._id}`
59383
+ });
59384
+ return `<a href="${href}">\${${field.name}.${NAME_FIELD_KEY}}</a>`
59385
+ }
59386
+
59018
59387
  }
59019
59388
 
59020
-
59021
- function isFieldTypeSearchable(fieldType) {
59022
- return !lodash.exports.includes(
59023
- [
59024
- "grid",
59025
- "avatar",
59026
- "image",
59027
- "object",
59028
- "[object]",
59029
- "[Object]",
59030
- "[grid]",
59031
- "[text]",
59032
- "audio",
59033
- "file",
59034
- ],
59035
- fieldType
59036
- )
59389
+ function getSwitchTpl(field){
59390
+ let fieldDataStrTpl = `data._display.${field.name}`;
59391
+ if(field.isTableField){
59392
+ fieldDataStrTpl = `data.${field.name}`;
59393
+ }
59394
+ return `<% if (data.${field.name}) { %>
59395
+ <span class="slds-icon_container slds-icon-utility-check slds-current-color" title="<%=${fieldDataStrTpl}%>">
59396
+ <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>
59397
+ </span>
59398
+ <% } %>`
59037
59399
  }
59038
59400
 
59039
- if (typeof window != 'undefined') {
59040
- window.isFieldTypeSearchable = isFieldTypeSearchable;
59401
+ function getPasswordTpl(field){
59402
+ return `<% if (data.${field.name}) { %>
59403
+ <span>······</span>
59404
+ <% } %>`
59041
59405
  }
59042
59406
 
59407
+ function getLocationTpl(field){
59408
+ return `\${${field.name} ? ${field.name}.address : ''}`
59409
+ }
59043
59410
 
59044
- function isFieldQuickSearchable(field, nameFieldKey) {
59045
- let fieldSearchable = field.searchable;
59046
- if(fieldSearchable !== false && field.name === nameFieldKey){
59047
- // 对象上名称字段的searchable默认认为是true
59048
- fieldSearchable = true;
59411
+ async function getFieldTpl (field, options){
59412
+ if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLookLabel){
59413
+ return getNameTpl(field, options)
59049
59414
  }
59050
- if (fieldSearchable && QUICK_SEARCHABLE_FIELD_TYPES.indexOf(field.type) > -1) {
59051
- return true;
59415
+ switch (field.type) {
59416
+ case 'password':
59417
+ return getPasswordTpl(field);
59418
+ case 'boolean':
59419
+ return getSwitchTpl(field);
59420
+ case 'toggle':
59421
+ return getSwitchTpl(field);
59422
+ case 'select':
59423
+ return getSelectTpl(field);
59424
+ case 'time':
59425
+ return getTimeTpl(field);
59426
+ case 'date':
59427
+ return getDateTpl(field);
59428
+ case 'datetime':
59429
+ return getDateTimeTpl(field);
59430
+ case 'lookup':
59431
+ return await getRelatedFieldTpl(field, options);
59432
+ case 'master_detail':
59433
+ return await getRelatedFieldTpl(field, options);
59434
+ case 'location':
59435
+ return await getLocationTpl(field);
59436
+ case 'number':
59437
+ case 'currency':
59438
+ return await getNumberTpl(field);
59439
+ case 'percent':
59440
+ case 'formula':
59441
+ case 'summary':
59442
+ return getUiFieldTpl(field)
59443
+ case 'filesize':
59444
+ return getUiFileSizeTpl(field)
59052
59445
  }
59053
- return false;
59054
59446
  }
59055
59447
 
59056
59448
  /*
@@ -59503,7 +59895,7 @@ function getFieldWidth(width){
59503
59895
 
59504
59896
  async function getTableColumns(fields, options){
59505
59897
  const columns = [];
59506
- if(!options.isLookup){
59898
+ if(!options.isLookup && !options.isInputTable){
59507
59899
  //将_display放入crud的columns中,可以通过setvalue修改行内数据域的_display,而不影响上层items的_display,用于批量编辑
59508
59900
  columns.push({name: '_display',type: 'static', width: 32, placeholder: "",id: "_display_${_index}", className: "hidden"});
59509
59901
  columns.push({name: '_index',type: 'text', width: 32, placeholder: ""});
@@ -59646,7 +60038,7 @@ async function getTableColumns(fields, options){
59646
60038
  }
59647
60039
  }
59648
60040
  // columns.push(getOperation(fields));
59649
- if(!options.isLookup && !lodash.exports.some(columns, { name: options.labelFieldName })){
60041
+ if(!options.isLookup && !options.isInputTable && !lodash.exports.some(columns, { name: options.labelFieldName })){
59650
60042
  // 没有名称字段时显示序号字段为链接,lookup弹出的picker不需要此功能
59651
60043
  const href = Router.getObjectDetailPath({
59652
60044
  ...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
@@ -59830,624 +60222,232 @@ async function getMobileTableColumns(fields, options){
59830
60222
  "api": {
59831
60223
  "url": url,
59832
60224
  "method": "get",
59833
- "headers": {
59834
- "Authorization": "Bearer ${context.tenantId},${context.authToken}"
59835
- }
59836
- }
59837
- },
59838
- "actionType": "download"
59839
- }
59840
- ],
59841
- "weight": 0
59842
- }
59843
- }
59844
- };
59845
- }
59846
-
59847
- }
59848
-
59849
- columns.push(column);
59850
-
59851
-
59852
- return columns;
59853
- }
59854
-
59855
- function getDefaultParams(options){
59856
- return {
59857
- perPage: options.top || options.perPage || config.listView.perPage
59858
- }
59859
- }
59860
-
59861
- function getButtonVisibleOn(button){
59862
- let visible= button.visible;
59863
-
59864
- if(button._visible){
59865
- visible = button._visible;
59866
- }
59867
-
59868
- if(lodash.exports.isBoolean(visible)){
59869
- visible = visible.toString();
59870
- }
59871
-
59872
- if(visible){
59873
- // if(visible.indexOf("Meteor.") > 0 || visible.indexOf("Creator.") > 0 || visible.indexOf("Session.") > 0){
59874
- // console.warn('无效的visible', visible)
59875
- // return 'false';
59876
- // }
59877
- if(visible.trim().startsWith('function')){
59878
- return `${visible}(objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
59879
- }
59880
- return visible;
59881
- }
59882
-
59883
- if(button.type === 'amis_button'){
59884
- const amisSchema = button.amis_schema;
59885
- if(amisSchema && amisSchema.body && amisSchema.body.length > 0){
59886
- const btn1 = amisSchema.body[0];
59887
- return btn1.visibleOn
59888
- }
59889
- }
59890
- }
59891
-
59892
- async function getTableOperation(ctx){
59893
- const buttons = ctx.buttons;
59894
- const operationButtons = [];
59895
- lodash.exports.each(buttons, (button)=>{
59896
- if(lodash.exports.isBoolean(button.visible)){
59897
- button.visible = button.visible.toString();
59898
- }
59899
- // operationButtons.push({
59900
- // type: 'button',
59901
- // label: button.label,
59902
- // visibleOn: button.visible ? `${button.visible}` : (button._visible ? `${button._visible}` : null),
59903
- // onEvent: {
59904
- // click: {
59905
- // actions: []
59906
- // }
59907
- // }
59908
- // })
59909
-
59910
- operationButtons.push({
59911
- type: 'steedos-object-button',
59912
- name: button.name,
59913
- objectName: button.objectName,
59914
- visibleOn: getButtonVisibleOn(button),
59915
- className: 'antd-Button--default'
59916
- });
59917
- });
59918
- if(operationButtons.length < 1){
59919
- return ;
59920
- }
59921
- return {
59922
- type: 'operation',
59923
- label: "",
59924
- fixed: 'right',
59925
- labelClassName: 'text-center',
59926
- className: 'text-center steedos-listview-operation w-10',
59927
- buttons: [
59928
- {
59929
- "type": "steedos-dropdown-button",
59930
- "label": "xxx",
59931
- "buttons": operationButtons,
59932
- "placement": "bottomRight",
59933
- "overlayClassName": "shadow !min-w-[160px]",
59934
- "trigger": ["click"],
59935
- "id": "u:c2140a365019",
59936
- onOpenApi: {
59937
- url: `\${context.rootUrl}/service/api/@\${objectName}/recordPermissions/\${_id}`,
59938
- method: "get",
59939
- requestAdaptor: "api.data={}; return api;",
59940
- headers: {
59941
- Authorization: "Bearer ${context.tenantId},${context.authToken}"
59942
- },
59943
- adaptor: `
59944
- payload = {
59945
- record: {
59946
- recordPermissions: payload
59947
- }
59948
- };
59949
- return payload;
59950
- `,
59951
- }
59952
- }
59953
- ]
59954
- }
59955
- }
59956
-
59957
- async function getDefaultCrudCard(columns, options) {
59958
- let labelFieldName = options?.labelFieldName || "name";
59959
- let titleColumn, bodyColumns = [];
59960
- columns.forEach(function (item) {
59961
- delete item.quickEdit;
59962
- delete item.width;
59963
- if (item.name === labelFieldName) {
59964
- titleColumn = item;
59965
- }
59966
- else {
59967
- if (item.name !== "_index") {
59968
- bodyColumns.push(item);
59969
- }
59970
- }
59971
- });
59972
- let card = {
59973
- "header": {
59974
- "title": titleColumn.tpl
59975
- },
59976
- body: bodyColumns,
59977
- // useCardLabel: false,
59978
- toolbar: []
59979
- };
59980
- let hideToolbarOperation = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
59981
- if(!hideToolbarOperation){
59982
- let toolbarOperation = await getTableOperation(options);
59983
- if (toolbarOperation) {
59984
- toolbarOperation.className += " inline-block w-auto";
59985
- }
59986
- card.toolbar.push(toolbarOperation);
59987
- }
59988
- return card;
59989
- }
59990
-
59991
- async function getTableSchema$1(fields, options){
59992
- if(!options){
59993
- options = {};
59994
- }
59995
- let { isLookup, hiddenColumnOperation } = options;
59996
- const defaults = options.defaults;
59997
- const listSchema = (defaults && defaults.listSchema) || {};
59998
-
59999
- let columns = [];
60000
- let useMobileColumns = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
60001
- if(isLookup){
60002
- // 在lookup手机端列表模式调式好之前不使用getMobileTableColumns
60003
- useMobileColumns = false;
60004
- }
60005
- if(listSchema.mode && listSchema.mode !== "table"){
60006
- // 如果指定的mode,则不走我们内置的手机端列表效果,使用steedos组件内部开发的默认card/list效果,或者由用户自己实现card/list模式的crud列表
60007
- useMobileColumns = false;
60008
- }
60009
- if(useMobileColumns){
60010
- columns = await getMobileTableColumns(fields, options);
60011
- }
60012
- else {
60013
- columns = await getTableColumns(fields, options);
60014
-
60015
- if(listSchema.mode === "cards"){
60016
- let card = listSchema.card;
60017
- if(!card){
60018
- card = await getDefaultCrudCard(columns, options);
60019
- }
60020
- return {
60021
- mode: "cards",
60022
- perPageAvailable: [5, 10, 20, 50, 100, 500],
60023
- name: "thelist",
60024
- headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
60025
- className: "",
60026
- draggable: false,
60027
- defaultParams: getDefaultParams(options),
60028
- card: card,
60029
- syncLocation: false,
60030
- keepItemSelectionOnPageChange: true,
60031
- checkOnItemClick: isLookup ? true : false,
60032
- labelTpl: `\${${options.labelFieldName}}`,
60033
- autoFillHeight: false, // 自动高度效果不理想,先关闭
60034
- columnsTogglable: false
60035
- }
60036
- }
60037
-
60038
- if(!isLookup && !hiddenColumnOperation){
60039
- columns.push(await getTableOperation(options));
60040
- }
60041
- }
60042
-
60043
- return {
60044
- mode: "table",
60045
- perPageAvailable: [5, 10, 20, 50, 100, 500],
60046
- name: "thelist",
60047
- headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
60048
- className: "",
60049
- draggable: false,
60050
- defaultParams: getDefaultParams(options),
60051
- columns: columns,
60052
- syncLocation: false,
60053
- keepItemSelectionOnPageChange: true,
60054
- checkOnItemClick: isLookup ? true : false,
60055
- labelTpl: `\${${options.labelFieldName}}`,
60056
- autoFillHeight: false, // 自动高度效果不理想,先关闭
60057
- columnsTogglable: false,
60058
- }
60059
- }
60060
-
60061
- /******************************************************************************
60062
- Copyright (c) Microsoft Corporation.
60063
-
60064
- Permission to use, copy, modify, and/or distribute this software for any
60065
- purpose with or without fee is hereby granted.
60066
-
60067
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
60068
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
60069
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
60070
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
60071
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
60072
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
60073
- PERFORMANCE OF THIS SOFTWARE.
60074
- ***************************************************************************** */
60075
-
60076
- var __assign = function() {
60077
- __assign = Object.assign || function __assign(t) {
60078
- for (var s, i = 1, n = arguments.length; i < n; i++) {
60079
- s = arguments[i];
60080
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
60081
- }
60082
- return t;
60083
- };
60084
- return __assign.apply(this, arguments);
60085
- };
60086
-
60087
- // 方便取值的时候能够把上层的取到,但是获取的时候不会全部把所有的数据获取到。
60088
- function createObject(superProps, props, properties) {
60089
- if (superProps && Object.isFrozen(superProps)) {
60090
- superProps = cloneObject(superProps);
60225
+ "headers": {
60226
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
60227
+ }
60228
+ }
60229
+ },
60230
+ "actionType": "download"
60231
+ }
60232
+ ],
60233
+ "weight": 0
60234
+ }
60235
+ }
60236
+ };
60237
+ }
60238
+
60091
60239
  }
60092
- var obj = superProps
60093
- ? Object.create(superProps, __assign(__assign({}, properties), { __super: {
60094
- value: superProps,
60095
- writable: false,
60096
- enumerable: false
60097
- } }))
60098
- : Object.create(Object.prototype, properties);
60099
- props &&
60100
- isObject(props) &&
60101
- Object.keys(props).forEach(function (key) { return (obj[key] = props[key]); });
60102
- return obj;
60103
- }
60104
- function cloneObject(target, persistOwnProps) {
60105
- if (persistOwnProps === void 0) { persistOwnProps = true; }
60106
- var obj = target && target.__super
60107
- ? Object.create(target.__super, {
60108
- __super: {
60109
- value: target.__super,
60110
- writable: false,
60111
- enumerable: false
60112
- }
60113
- })
60114
- : Object.create(Object.prototype);
60115
- persistOwnProps &&
60116
- target &&
60117
- Object.keys(target).forEach(function (key) { return (obj[key] = target[key]); });
60118
- return obj;
60119
- }
60120
- function isObject(obj) {
60121
- var typename = typeof obj;
60122
- return (obj &&
60123
- typename !== 'string' &&
60124
- typename !== 'number' &&
60125
- typename !== 'boolean' &&
60126
- typename !== 'function' &&
60127
- !Array.isArray(obj));
60128
- }
60129
-
60130
- /*
60131
- * @Author: baozhoutao@steedos.com
60132
- * @Date: 2022-07-05 15:55:39
60133
- * @LastEditors: liaodaxue
60134
- * @LastEditTime: 2023-10-20 11:38:25
60135
- * @Description:
60136
- */
60137
60240
 
60138
- let UI_SCHEMA_CACHE = {};
60241
+ columns.push(column);
60242
+
60139
60243
 
60140
- let UISchemaFunction;
60244
+ return columns;
60245
+ }
60141
60246
 
60142
- if('undefined' != typeof window){
60143
- if(!window.UI_SCHEMA_CACHE){
60144
- window.UI_SCHEMA_CACHE = UI_SCHEMA_CACHE;
60247
+ function getDefaultParams(options){
60248
+ return {
60249
+ perPage: options.top || options.perPage || config.listView.perPage
60145
60250
  }
60146
- UI_SCHEMA_CACHE = window.UI_SCHEMA_CACHE;
60147
60251
  }
60148
60252
 
60149
- const setUISchemaCache = (key, value) => {
60150
- UI_SCHEMA_CACHE[key] = value;
60151
- };
60152
-
60153
- const getUISchemaCache = (key) => {
60154
- return lodash.exports.cloneDeep(UI_SCHEMA_CACHE[key]);
60155
- };
60156
-
60157
- const hasUISchemaCache = (key) => {
60158
- return lodash.exports.has(UI_SCHEMA_CACHE, key);
60159
- };
60253
+ function getButtonVisibleOn(button){
60254
+ let visible= button.visible;
60160
60255
 
60161
- function getListViewColumns(listView, formFactor) {
60162
- let listViewColumns = [];
60163
- if (formFactor === "SMALL") {
60164
- listViewColumns = !lodash.exports.isEmpty(listView.mobile_columns)
60165
- ? listView.mobile_columns
60166
- : lodash.exports.slice(listView.columns, 0, 4);
60167
- } else {
60168
- listViewColumns = listView.columns;
60256
+ if(button._visible){
60257
+ visible = button._visible;
60169
60258
  }
60170
- return listViewColumns;
60171
- }
60172
- function getListViewSort(listView) {
60173
- let sort = '';
60174
- if(listView && listView.sort && listView.sort.length){
60175
- lodash.exports.each(listView.sort,function(item,index){
60176
- if(lodash.exports.isArray(item)){
60177
- const field_name = item[0];
60178
- const order = item[1] || '';
60179
- let sortStr = field_name + ' ' + order;
60180
- sortStr = index > 0 ? ','+sortStr : sortStr;
60181
- sort += sortStr;
60182
- }else {
60183
- let sortStr = item.field_name + ' ' + item.order;
60184
- sortStr = index > 0 ? ','+sortStr : sortStr;
60185
- sort += sortStr;
60186
- }
60187
- });
60259
+
60260
+ if(lodash.exports.isBoolean(visible)){
60261
+ visible = visible.toString();
60188
60262
  }
60189
- return sort;
60190
- }
60191
- function getListViewFilter(listView){
60192
- if(!listView){
60193
- return ;
60263
+
60264
+ if(visible){
60265
+ // if(visible.indexOf("Meteor.") > 0 || visible.indexOf("Creator.") > 0 || visible.indexOf("Session.") > 0){
60266
+ // console.warn('无效的visible', visible)
60267
+ // return 'false';
60268
+ // }
60269
+ if(visible.trim().startsWith('function')){
60270
+ return `${visible}(objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
60271
+ }
60272
+ return visible;
60194
60273
  }
60195
- try {
60196
- const userId = getUserId();
60197
- let filters = listView.filters;
60198
- if(listView.filter_scope === 'mine'){
60199
- if(___default.isEmpty(filters)){
60200
- filters = [["owner", "=", userId]];
60201
- }else {
60202
- if(___default.isString(filters) && ___default.startsWith(___default.trim(filters), "function")){
60203
- filters = new Function(`return ${filters}`);
60204
- filters = filters();
60205
- }
60206
- if(___default.isArray(filters)){
60207
- filters.push(["owner", "=", userId]);
60208
- }else {
60209
- console.debug(`listView filters is not array`, listView);
60210
- throw new Error('filters is not array')
60211
- }
60212
- }
60213
- };
60214
- return filters;
60215
- } catch (error) {
60216
- console.error(error);
60274
+
60275
+ if(button.type === 'amis_button'){
60276
+ const amisSchema = button.amis_schema;
60277
+ if(amisSchema && amisSchema.body && amisSchema.body.length > 0){
60278
+ const btn1 = amisSchema.body[0];
60279
+ return btn1.visibleOn
60280
+ }
60217
60281
  }
60218
60282
  }
60219
60283
 
60220
- function formatUISchemaCache(objectName, uiSchema){
60221
- setUISchemaCache(objectName, uiSchema);
60222
- lodash.exports.each(uiSchema.fields, (field)=>{
60223
- try {
60224
- if(field.type === "lookup" && field._reference_to && ___default.isString(field._reference_to)){
60225
- field.reference_to = eval(`(${field._reference_to})`)();
60226
- }
60227
- } catch (exception) {
60228
- field.reference_to = undefined;
60229
- console.error(exception);
60230
- }
60231
- });
60232
- lodash.exports.each(uiSchema.list_views, (v, k)=>{
60233
- v.name = k;
60234
- if(!lodash.exports.has(v, 'columns')){
60235
- v.columns = uiSchema.list_views.all.columns;
60284
+ async function getTableOperation(ctx){
60285
+ const buttons = ctx.buttons;
60286
+ const operationButtons = [];
60287
+ lodash.exports.each(buttons, (button)=>{
60288
+ if(lodash.exports.isBoolean(button.visible)){
60289
+ button.visible = button.visible.toString();
60236
60290
  }
60237
- });
60238
- }
60291
+ // operationButtons.push({
60292
+ // type: 'button',
60293
+ // label: button.label,
60294
+ // visibleOn: button.visible ? `${button.visible}` : (button._visible ? `${button._visible}` : null),
60295
+ // onEvent: {
60296
+ // click: {
60297
+ // actions: []
60298
+ // }
60299
+ // }
60300
+ // })
60239
60301
 
60240
- async function getUISchema(objectName, force) {
60241
- if (!objectName) {
60242
- return;
60243
- }
60244
- if (hasUISchemaCache(objectName) && !force) {
60245
- return getUISchemaCache(objectName);
60302
+ operationButtons.push({
60303
+ type: 'steedos-object-button',
60304
+ name: button.name,
60305
+ objectName: button.objectName,
60306
+ visibleOn: getButtonVisibleOn(button),
60307
+ className: 'antd-Button--default'
60308
+ });
60309
+ });
60310
+ if(operationButtons.length < 1){
60311
+ return ;
60246
60312
  }
60247
- let uiSchema = null;
60248
- try {
60249
- if(UISchemaFunction);
60250
- else {
60251
- const url = `/service/api/@${objectName.replace(/\./g, "_")}/uiSchema`;
60252
- uiSchema = await fetchAPI(url, { method: "get" });
60253
- }
60254
- if(!uiSchema){
60255
- return ;
60256
- }
60257
- formatUISchemaCache(objectName, uiSchema);
60258
- } catch (error) {
60259
- console.error(`getUISchema`, objectName, error);
60260
- setUISchemaCache(objectName, null);
60313
+ return {
60314
+ type: 'operation',
60315
+ label: "&nbsp;",
60316
+ fixed: 'right',
60317
+ labelClassName: 'text-center',
60318
+ className: 'text-center steedos-listview-operation w-10',
60319
+ buttons: [
60320
+ {
60321
+ "type": "steedos-dropdown-button",
60322
+ "label": "xxx",
60323
+ "buttons": operationButtons,
60324
+ "placement": "bottomRight",
60325
+ "overlayClassName": "shadow !min-w-[160px]",
60326
+ "trigger": ["click"],
60327
+ "id": "u:c2140a365019",
60328
+ onOpenApi: {
60329
+ url: `\${context.rootUrl}/service/api/@\${objectName}/recordPermissions/\${_id}`,
60330
+ method: "get",
60331
+ requestAdaptor: "api.data={}; return api;",
60332
+ headers: {
60333
+ Authorization: "Bearer ${context.tenantId},${context.authToken}"
60334
+ },
60335
+ adaptor: `
60336
+ payload = {
60337
+ record: {
60338
+ recordPermissions: payload
60339
+ }
60340
+ };
60341
+ return payload;
60342
+ `,
60343
+ }
60344
+ }
60345
+ ]
60261
60346
  }
60262
- return getUISchemaCache(objectName);
60263
60347
  }
60264
60348
 
60265
- function getUISchemaSync(objectName, force) {
60266
- if (!objectName) {
60267
- return;
60268
- }
60269
- if (hasUISchemaCache(objectName) && !force) {
60270
- return getUISchemaCache(objectName);
60271
- }
60272
- let uiSchema = null;
60273
- try {
60274
-
60275
- const url = `/service/api/@${objectName.replace(/\./g, "_")}/uiSchema`;
60276
- uiSchema = Steedos.authRequest(url, {
60277
- type: 'GET',
60278
- async: false,
60279
- });
60280
-
60281
- if(!uiSchema){
60282
- return ;
60349
+ async function getDefaultCrudCard(columns, options) {
60350
+ let labelFieldName = options?.labelFieldName || "name";
60351
+ let titleColumn, bodyColumns = [];
60352
+ columns.forEach(function (item) {
60353
+ delete item.quickEdit;
60354
+ delete item.width;
60355
+ if (item.name === labelFieldName) {
60356
+ titleColumn = item;
60283
60357
  }
60284
- formatUISchemaCache(objectName, uiSchema);
60285
- } catch (error) {
60286
- console.error(`getUISchema`, objectName, error);
60287
- setUISchemaCache(objectName, null);
60358
+ else {
60359
+ if (item.name !== "_index") {
60360
+ bodyColumns.push(item);
60361
+ }
60362
+ }
60363
+ });
60364
+ let card = {
60365
+ "header": {
60366
+ "title": titleColumn.tpl
60367
+ },
60368
+ body: bodyColumns,
60369
+ // useCardLabel: false,
60370
+ toolbar: []
60371
+ };
60372
+ let hideToolbarOperation = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
60373
+ if(!hideToolbarOperation){
60374
+ let toolbarOperation = await getTableOperation(options);
60375
+ if (toolbarOperation) {
60376
+ toolbarOperation.className += " inline-block w-auto";
60377
+ }
60378
+ card.toolbar.push(toolbarOperation);
60288
60379
  }
60289
- return getUISchemaCache(objectName);
60380
+ return card;
60290
60381
  }
60291
60382
 
60292
- // 获取列表视图
60293
- async function getListSchema(
60294
- appName,
60295
- objectName,
60296
- listViewName,
60297
- ctx = {}
60298
- ) {
60299
- const uiSchema = await getUISchema(objectName);
60300
- if(!uiSchema){
60301
- return {}
60383
+ async function getTableSchema(fields, options){
60384
+ if(!options){
60385
+ options = {};
60302
60386
  }
60303
- const listView = lodash.exports.find(
60304
- uiSchema.list_views,
60305
- (listView, name) => {
60306
- // 传入listViewName空值则取第一个
60307
- if(!listViewName){
60308
- listViewName = name;
60309
- }
60310
- return name === listViewName || listView._id === listViewName;
60311
- }
60312
- );
60387
+ let { isLookup, hiddenColumnOperation } = options;
60388
+ const defaults = options.defaults;
60389
+ const listSchema = (defaults && defaults.listSchema) || {};
60313
60390
 
60314
- if (!listView) {
60315
- return { uiSchema };
60391
+ let columns = [];
60392
+ let useMobileColumns = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
60393
+ if(isLookup){
60394
+ // 在lookup手机端列表模式调式好之前不使用getMobileTableColumns
60395
+ useMobileColumns = false;
60316
60396
  }
60317
-
60318
- // 直接返回自定义的列表视图schema
60319
- if(listView.enable_amis_schema && listView.amis_schema){
60320
- const amisSchema = lodash.exports.isString(listView.amis_schema) ? JSON.parse(listView.amis_schema) : listView.amis_schema;
60321
- return {
60322
- uiSchema,
60323
- isCustomAmisSchema: true,
60324
- amisSchema
60325
- };
60397
+ if(listSchema.mode && listSchema.mode !== "table"){
60398
+ // 如果指定的mode,则不走我们内置的手机端列表效果,使用steedos组件内部开发的默认card/list效果,或者由用户自己实现card/list模式的crud列表
60399
+ useMobileColumns = false;
60326
60400
  }
60327
-
60328
- let listViewColumns = getListViewColumns(listView, ctx.formFactor);
60329
- let sort = getListViewSort(listView);
60330
- let listviewFilter = getListViewFilter(listView);
60331
- let listview_filters = listView && listView._filters;
60332
- // 返回 calendar 组件
60333
- if(listView.type === "calendar"){
60334
- const amisSchema = {
60335
- "type": "steedos-object-calendar",
60336
- "objectApiName": objectName,
60337
- "filters": listviewFilter,
60338
- "filtersFunction": listview_filters,
60339
- "sort": sort,
60340
- ...listView.options
60341
- };
60342
- return {
60343
- uiSchema,
60344
- isCalendar: true,
60345
- amisSchema
60346
- };
60401
+ if(useMobileColumns){
60402
+ columns = await getMobileTableColumns(fields, options);
60347
60403
  }
60404
+ else {
60405
+ columns = await getTableColumns(fields, options);
60348
60406
 
60349
- const defaults = ctx.defaults || {};
60350
-
60351
- // // 未自定义header 且显示header的时候, 使用系统header
60352
- // if(!defaults.headerSchema && ctx.showHeader){
60353
- // defaults.headerSchema = getObjectListHeader(uiSchema, listViewName);
60354
- // }
60355
-
60356
- // // 如果不显示header,则清理掉
60357
- // if(!ctx.showHeader){
60358
- // defaults.headerSchema = null;
60359
- // }
60360
-
60361
- defaults.headerSchema = null;
60362
-
60363
- /**
60364
- * 本次存储代码段
60365
- */
60366
- try {
60367
- const listViewPropsStoreKey = location.pathname + "/crud";
60368
- let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
60369
- /**
60370
- * localListViewProps规范来自crud请求api中api.data.$self参数值的。
60371
- * 比如:{"perPage":20,"page":1,"__searchable__name":"7","__searchable__between__n1__c":[null,null],"filter":[["name","contains","a"]]}
60372
- * __searchable__...:顶部放大镜搜索条件
60373
- * filter:右侧过滤器
60374
- * perPage:每页条数
60375
- * page:当前页码
60376
- * orderBy:排序字段
60377
- * orderDir:排序方向
60378
- */
60379
- if (localListViewProps) {
60380
- localListViewProps = JSON.parse(localListViewProps);
60381
- // localListViewProps.perPage = 3;
60382
- let listSchema = {};
60383
- if(localListViewProps.orderBy){
60384
- listSchema.orderBy = localListViewProps.orderBy;
60385
- }
60386
- if(localListViewProps.orderDir){
60387
- listSchema.orderDir = localListViewProps.orderDir;
60407
+ if(listSchema.mode === "cards"){
60408
+ let card = listSchema.card;
60409
+ if(!card){
60410
+ card = await getDefaultCrudCard(columns, options);
60411
+ }
60412
+ return {
60413
+ mode: "cards",
60414
+ perPageAvailable: [5, 10, 20, 50, 100, 500],
60415
+ name: "thelist",
60416
+ headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
60417
+ className: "",
60418
+ draggable: false,
60419
+ defaultParams: getDefaultParams(options),
60420
+ card: card,
60421
+ syncLocation: false,
60422
+ keepItemSelectionOnPageChange: true,
60423
+ checkOnItemClick: isLookup ? true : false,
60424
+ labelTpl: `\${${options.labelFieldName}}`,
60425
+ autoFillHeight: false, // 自动高度效果不理想,先关闭
60426
+ columnsTogglable: false
60427
+ }
60388
60428
  }
60389
60429
 
60390
- if(localListViewProps.perPage){
60391
- listSchema.defaultParams = {
60392
- perPage: localListViewProps.perPage
60393
- };
60430
+ if(!isLookup && !hiddenColumnOperation){
60431
+ columns.push(await getTableOperation(options));
60394
60432
  }
60395
- defaults.listSchema = lodash.exports.defaultsDeep({}, listSchema, defaults.listSchema || {});
60396
- }
60397
- }
60398
- catch (ex) {
60399
- console.error("本地存储中crud参数解析异常:", ex);
60400
60433
  }
60401
60434
 
60402
- ctx.defaults = defaults;
60403
-
60404
- if (listViewName == "recent") {
60405
- listview_filters = `
60406
- function(filters, data) {
60407
- var result = Steedos.authRequest('/graphql', {
60408
- type: 'POST',
60409
- async: false,
60410
- data: JSON.stringify({
60411
- query: '{object_recent_viewed(filters: [["record.o","=","' + data.objectName + '"],["space","=","' + data.context.tenantId + '"],["owner","=","' + data.context.userId + '"]],sort:"modified desc",top:50){ _id,record} }'
60412
- }),
60413
- });
60414
- var _ids = []
60415
- result.data.object_recent_viewed.forEach(function (item) {
60416
- _ids = _ids.concat(item.record.ids)
60417
- })
60418
- return ["_id", "=", _ids];
60419
- }
60420
- `;
60421
- }
60422
- const amisSchema = {
60423
- "type": "steedos-object-table",
60424
- "objectApiName": objectName,
60425
- "columns": listViewColumns,
60426
- "extraColumns": listView.extra_columns,
60427
- "filters": listviewFilter,
60428
- "filtersFunction": listview_filters,
60429
- "sort": sort,
60430
- "ctx": ctx,
60431
- "requestAdaptor": listView.requestAdaptor || ctx.requestAdaptor,
60432
- "adaptor": listView.adaptor || ctx.adaptor,
60433
- "headerToolbarItems": ctx.headerToolbarItems,
60434
- "filterVisible": ctx.filterVisible,
60435
- "rowClassNameExpr": ctx.rowClassNameExpr,
60436
- "crudDataFilter": ctx.crudDataFilter,
60437
- "onCrudDataFilter": ctx.onCrudDataFilter
60438
- };
60439
- // console.log(`getListSchema===>`,amisSchema)
60440
60435
  return {
60441
- uiSchema,
60442
- amisSchema,
60443
- };
60444
- }
60445
-
60446
-
60447
- if(typeof window != 'undefined'){
60448
- window.getUISchema = getUISchema;
60449
- window.getUISchemaSync = getUISchemaSync;
60450
- window.getListSchema = getListSchema;
60436
+ mode: "table",
60437
+ perPageAvailable: [5, 10, 20, 50, 100, 500],
60438
+ name: "thelist",
60439
+ headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
60440
+ className: "",
60441
+ draggable: false,
60442
+ defaultParams: getDefaultParams(options),
60443
+ columns: columns,
60444
+ syncLocation: false,
60445
+ keepItemSelectionOnPageChange: true,
60446
+ checkOnItemClick: isLookup ? true : false,
60447
+ labelTpl: `\${${options.labelFieldName}}`,
60448
+ autoFillHeight: false, // 自动高度效果不理想,先关闭
60449
+ columnsTogglable: false,
60450
+ }
60451
60451
  }
60452
60452
 
60453
60453
  function useCombinedRefs(...refs) {