@steedos-widgets/sortable 1.3.9 → 1.3.11

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