Skip to content

Commit

Permalink
处理手机app上图片、附件字段异常问题
Browse files Browse the repository at this point in the history
  • Loading branch information
baozhoutao committed Oct 14, 2024
1 parent 4e36174 commit 7991be2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
10 changes: 5 additions & 5 deletions packages/@steedos-widgets/amis-lib/src/lib/converter/amis/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function getReadonlyFormAdaptor(object, fields, options){
var gridAndObjectFieldsName = ${JSON.stringify(gridAndObjectFieldsName)};
try{
${scriptStr}
${getScriptForAddUrlPrefixForImgFields(fields)}
${getScriptForAddUrlPrefixForImgFields(fields, true)}
${getScriptForRewriteValueForFileFields(fields)}
}catch(e){
console.error(e)
Expand Down Expand Up @@ -161,7 +161,7 @@ function getConvertDataScriptStr(fields){
/*
img/avatar字段值添加URL前缀使其在amis中正常显示图片。
*/
export function getScriptForAddUrlPrefixForImgFields(fields){
export function getScriptForAddUrlPrefixForImgFields(fields, readonly){
let imgFieldsKeys = [];
let imgFields = {};
fields.forEach((item)=>{
Expand Down Expand Up @@ -189,12 +189,12 @@ export function getScriptForAddUrlPrefixForImgFields(fields){
if(fieldProps.multiple){
if(imgFieldDisplayValue instanceof Array){
data[item] = imgFieldDisplayValue.map((i)=>{
const url = window.getImageFieldUrl(i.url);
const url = window.getImageFieldUrl(i.url, ${readonly});
return url;
});
}
}else{
const url = imgFieldDisplayValue && window.getImageFieldUrl(imgFieldDisplayValue.url);
const url = imgFieldDisplayValue && window.getImageFieldUrl(imgFieldDisplayValue.url, ${readonly});
data[item] = url;
}
}
Expand Down Expand Up @@ -290,7 +290,7 @@ export async function getEditFormInitApi(object, recordId, fields, options){
const fieldKeys = uiSchema && _.keys(uiSchema.fields);
if(data){
${getScriptForAddUrlPrefixForImgFields(fields)}
${getScriptForAddUrlPrefixForImgFields(fields, false)}
${getScriptForRewriteValueForFileFields(fields)}
_.each(dataKeys, function(key){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: [email protected]
* @Date: 2022-10-28 14:15:09
* @LastEditors: [email protected]
* @LastEditTime: 2024-08-19 16:26:58
* @LastEditTime: 2024-10-14 14:01:15
* @Description:
*/
import { getAmisStaticFieldType } from './type';
Expand Down Expand Up @@ -104,13 +104,13 @@ export const getAmisFileReadonlySchema = async (steedosField,ctx = {})=>{
if(type === 'file'){
return window.Meteor?.isCordova ? {
"type": "control",
"body": {
"body": steedosField.multiple ? {
"type": "each",
"name": "_display." + steedosField.name,
"items": {
"type": "tpl",
"tpl": "${name}",
"className": "antd-Button--link inline-block",
"className": "antd-Button--link inline-block mr-2",
"onEvent": {
"click": {
"actions": [
Expand All @@ -125,6 +125,24 @@ export const getAmisFileReadonlySchema = async (steedosField,ctx = {})=>{
}
}
}
} : {
"type": "tpl",
"tpl": "${_display." + steedosField.name + ".name}",
"className": "antd-Button--link inline-block",
"onEvent": {
"click": {
"actions": [
{
"script": `
const data = event.data._display.${steedosField.name};
Steedos.cordovaDownload(encodeURI(data.url), data.name);
`,
"actionType": "custom"
}
],
"weight": 0
}
}
}
} : {
// type: amisFieldType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ export function getScriptForRemoveUrlPrefixForImgFields(fields){
if(imgFieldValue instanceof Array){
formData[item] = imgFieldValue.map((value)=>{
let itemValue = value && value.split('/');
return itemValue[itemValue.length - 1];
return itemValue[itemValue.length - 1].split('?')[0];
});
}
}else{
let imgValue = imgFieldValue.split('/');
formData[item] = imgValue[imgValue.length - 1];
formData[item] = imgValue[imgValue.length - 1].split('?')[0];
}
}
})
Expand Down
24 changes: 15 additions & 9 deletions packages/@steedos-widgets/amis-lib/src/lib/converter/amis/util.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author: [email protected]
* @Date: 2022-07-20 16:29:22
* @LastEditors: liaodaxue
* @LastEditTime: 2024-01-25 14:44:17
* @LastEditors: [email protected]
* @LastEditTime: 2024-10-14 13:33:27
* @Description:
*/
import { getRootUrl } from "../../steedos.client";
Expand All @@ -21,13 +21,19 @@ export function getSvgUrl(source, name) {
return `${getRootUrl()}${url}`;
}

export function getImageFieldUrl(url) {
if (window.Meteor && window.Meteor.isCordova != true) {
// '//'的位置
const doubleSlashIndex = url.indexOf('//');
const urlIndex = url.indexOf('/', doubleSlashIndex + 2);
const rootUrl = url.substring(urlIndex);
return rootUrl;
export function getImageFieldUrl(url, readonly) {
if (window.Meteor) {
if(window.Meteor.isCordova != true){
// '//'的位置
const doubleSlashIndex = url.indexOf('//');
const urlIndex = url.indexOf('/', doubleSlashIndex + 2);
const rootUrl = url.substring(urlIndex);
return rootUrl;
}else{
if(readonly || url.startsWith('http')){
return `${url}?token=${window.btoa(JSON.stringify({ authToken : Builder.settings.context.authToken }))}`
}
}
}
return url;
}
Expand Down

0 comments on commit 7991be2

Please sign in to comment.