Skip to content

Commit e3ba2ba

Browse files
committed
chore(lib): 添加 readonly 支持,修复upload组件默认为空问题
优化upload组件上传文件支持点击 re #50 #45
1 parent 485f337 commit e3ba2ba

File tree

23 files changed

+496
-281
lines changed

23 files changed

+496
-281
lines changed

packages/demo/demo-common/components/EditorHeader.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ export default {
6363
},
6464
methods: {
6565
handleVersionChange(val) {
66-
window.location.href = window.location.href.replace(
67-
`${window.location.origin}${val === 'vue3' ? '' : '/v3'}`,
68-
`${window.location.origin}${val === 'vue3' ? '/v3' : ''}`
69-
).replace(/&ui=.*?&/, '&');
66+
// eslint-disable-next-line no-unused-vars
67+
const { ui, ...query } = this.$route.query;
68+
const genRoute = this.$router.resolve({ query });
69+
window.location.href = `${(val === 'vue3' ? '/v3/' : '/')}${genRoute.href}`;
7070
},
7171
}
7272
};

packages/lib/utils/formUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ export function getUiOptions({
140140
}) {
141141
const spec = {};
142142
if (containsSpec) {
143+
spec.readonly = !!schema.readOnly;
143144
if (undefined !== schema.multipleOf) {
144-
// 组件计数器步长
145+
// 组件计数器步长
145146
spec.step = schema.multipleOf;
146147
}
147148
if (schema.minimum || schema.minimum === 0) {

packages/lib/utils/utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,14 @@ export function gcd(a, b) {
329329
export function scm(a, b) {
330330
return (a * b) / gcd(a, b);
331331
}
332+
333+
// 打开新页面
334+
export function openNewPage(url, target = '_blank') {
335+
const a = document.createElement('a');
336+
a.style.display = 'none';
337+
a.target = target;
338+
a.href = url;
339+
document.body.appendChild(a);
340+
a.click();
341+
document.body.removeChild(a);
342+
}

packages/lib/vue2/vue2-form-element/dist/vueJsonSchemaForm.esm.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,17 @@ function gcd(a, b) {
454454

455455
function scm(a, b) {
456456
return a * b / gcd(a, b);
457+
} // 打开新页面
458+
459+
function openNewPage(url) {
460+
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '_blank';
461+
var a = document.createElement('a');
462+
a.style.display = 'none';
463+
a.target = target;
464+
a.href = url;
465+
document.body.appendChild(a);
466+
a.click();
467+
document.body.removeChild(a);
457468
}
458469

459470
// $ref 引用
@@ -8521,6 +8532,8 @@ function getUiOptions(_ref5) {
85218532
var spec = {};
85228533

85238534
if (containsSpec) {
8535+
spec.readonly = !!schema.readOnly;
8536+
85248537
if (undefined !== schema.multipleOf) {
85258538
// 组件计数器步长
85268539
spec.step = schema.multipleOf;
@@ -11964,11 +11977,6 @@ var TimePickerWidget = {
1196411977
}
1196511978
};
1196611979

11967-
/**
11968-
* Created by Liu.Jun on 2020/11/26 10:01 下午.
11969-
*/
11970-
// mock
11971-
// https://run.mocky.io/v3/518d7af7-204f-45ab-9628-a6e121dab8ca
1197211980
var UploadWidget = {
1197311981
name: 'UploadWidget',
1197411982
props: {
@@ -11996,47 +12004,52 @@ var UploadWidget = {
1199612004
// 设置默认 fileList
1199712005
var value = this.value;
1199812006
var isArrayValue = Array.isArray(value);
11999-
var fileList = this.$attrs.fileList || [];
1200012007

12001-
if (isArrayValue) {
12002-
fileList = value.map(function (item, index) {
12003-
return {
12004-
name: "\u5DF2\u4E0A\u4F20\u6587\u4EF6\uFF08".concat(index + 1, "\uFF09"),
12005-
url: item
12006-
};
12007-
});
12008-
} else if (value) {
12009-
fileList.push({
12010-
name: '已上传文件',
12011-
url: value
12012-
});
12013-
}
12008+
var fileList = this.$attrs.fileList || function () {
12009+
if (isArrayValue) {
12010+
return value.map(function (item, index) {
12011+
return {
12012+
name: "\u5DF2\u4E0A\u4F20\u6587\u4EF6\uFF08".concat(index + 1, "\uFF09"),
12013+
url: item
12014+
};
12015+
});
12016+
}
12017+
12018+
if (value) {
12019+
return [{
12020+
name: '已上传文件',
12021+
url: value
12022+
}];
12023+
}
12024+
12025+
return [];
12026+
}();
1201412027

1201512028
return {
1201612029
isArrayValue: isArrayValue,
1201712030
fileList: fileList
1201812031
};
1201912032
},
1202012033
methods: {
12034+
getUrl: function getUrl(fileItem) {
12035+
return fileItem && (fileItem.response && this.responseFileUrl(fileItem.response) || fileItem.url) || '';
12036+
},
1202112037
emitValue: function emitValue(fileList) {
1202212038
var _this = this;
1202312039

1202412040
// v-model
1202512041
var value;
1202612042

12027-
var geUrl = function geUrl(fileItem) {
12028-
return fileItem && (fileItem.response && _this.responseFileUrl(fileItem.response) || fileItem.url) || '';
12029-
};
12030-
1203112043
if (this.isArrayValue) {
1203212044
value = fileList.length ? fileList.reduce(function (pre, item) {
12033-
var url = geUrl(item);
12045+
var url = _this.getUrl(item);
12046+
1203412047
if (url) pre.push(url);
1203512048
return pre;
1203612049
}, []) : [];
1203712050
} else {
1203812051
var fileItem = fileList[fileList.length - 1];
12039-
value = geUrl(fileItem);
12052+
value = this.getUrl(fileItem);
1204012053
}
1204112054

1204212055
this.$emit('input', value);
@@ -12060,6 +12073,11 @@ var UploadWidget = {
1206012073
if (_this2.$message) {
1206112074
_this2.$message.error('文件上传失败');
1206212075
}
12076+
},
12077+
'on-preview': function onPreview(file) {
12078+
var url = _this2.getUrl(file);
12079+
12080+
if (url) openNewPage(url);
1206312081
}
1206412082
}, attrs), {}, {
1206512083
'on-remove': function onRemove(file, fileList) {

packages/lib/vue2/vue2-form-element/dist/vueJsonSchemaForm.esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/lib/vue2/vue2-form-element/dist/vueJsonSchemaForm.umd.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,17 @@
462462

463463
function scm(a, b) {
464464
return a * b / gcd(a, b);
465+
} // 打开新页面
466+
467+
function openNewPage(url) {
468+
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '_blank';
469+
var a = document.createElement('a');
470+
a.style.display = 'none';
471+
a.target = target;
472+
a.href = url;
473+
document.body.appendChild(a);
474+
a.click();
475+
document.body.removeChild(a);
465476
}
466477

467478
// $ref 引用
@@ -8529,6 +8540,8 @@
85298540
var spec = {};
85308541

85318542
if (containsSpec) {
8543+
spec.readonly = !!schema.readOnly;
8544+
85328545
if (undefined !== schema.multipleOf) {
85338546
// 组件计数器步长
85348547
spec.step = schema.multipleOf;
@@ -11972,11 +11985,6 @@
1197211985
}
1197311986
};
1197411987

11975-
/**
11976-
* Created by Liu.Jun on 2020/11/26 10:01 下午.
11977-
*/
11978-
// mock
11979-
// https://run.mocky.io/v3/518d7af7-204f-45ab-9628-a6e121dab8ca
1198011988
var UploadWidget = {
1198111989
name: 'UploadWidget',
1198211990
props: {
@@ -12004,47 +12012,52 @@
1200412012
// 设置默认 fileList
1200512013
var value = this.value;
1200612014
var isArrayValue = Array.isArray(value);
12007-
var fileList = this.$attrs.fileList || [];
1200812015

12009-
if (isArrayValue) {
12010-
fileList = value.map(function (item, index) {
12011-
return {
12012-
name: "\u5DF2\u4E0A\u4F20\u6587\u4EF6\uFF08".concat(index + 1, "\uFF09"),
12013-
url: item
12014-
};
12015-
});
12016-
} else if (value) {
12017-
fileList.push({
12018-
name: '已上传文件',
12019-
url: value
12020-
});
12021-
}
12016+
var fileList = this.$attrs.fileList || function () {
12017+
if (isArrayValue) {
12018+
return value.map(function (item, index) {
12019+
return {
12020+
name: "\u5DF2\u4E0A\u4F20\u6587\u4EF6\uFF08".concat(index + 1, "\uFF09"),
12021+
url: item
12022+
};
12023+
});
12024+
}
12025+
12026+
if (value) {
12027+
return [{
12028+
name: '已上传文件',
12029+
url: value
12030+
}];
12031+
}
12032+
12033+
return [];
12034+
}();
1202212035

1202312036
return {
1202412037
isArrayValue: isArrayValue,
1202512038
fileList: fileList
1202612039
};
1202712040
},
1202812041
methods: {
12042+
getUrl: function getUrl(fileItem) {
12043+
return fileItem && (fileItem.response && this.responseFileUrl(fileItem.response) || fileItem.url) || '';
12044+
},
1202912045
emitValue: function emitValue(fileList) {
1203012046
var _this = this;
1203112047

1203212048
// v-model
1203312049
var value;
1203412050

12035-
var geUrl = function geUrl(fileItem) {
12036-
return fileItem && (fileItem.response && _this.responseFileUrl(fileItem.response) || fileItem.url) || '';
12037-
};
12038-
1203912051
if (this.isArrayValue) {
1204012052
value = fileList.length ? fileList.reduce(function (pre, item) {
12041-
var url = geUrl(item);
12053+
var url = _this.getUrl(item);
12054+
1204212055
if (url) pre.push(url);
1204312056
return pre;
1204412057
}, []) : [];
1204512058
} else {
1204612059
var fileItem = fileList[fileList.length - 1];
12047-
value = geUrl(fileItem);
12060+
value = this.getUrl(fileItem);
1204812061
}
1204912062

1205012063
this.$emit('input', value);
@@ -12068,6 +12081,11 @@
1206812081
if (_this2.$message) {
1206912082
_this2.$message.error('文件上传失败');
1207012083
}
12084+
},
12085+
'on-preview': function onPreview(file) {
12086+
var url = _this2.getUrl(file);
12087+
12088+
if (url) openNewPage(url);
1207112089
}
1207212090
}, attrs), {}, {
1207312091
'on-remove': function onRemove(file, fileList) {

0 commit comments

Comments
 (0)