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