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