From a4d3bf4b5c1895b3d74e960b315c243218000f56 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Wed, 25 Oct 2023 12:45:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=AB=AF=20extrafil?= =?UTF-8?q?e/commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/components/extraFile/commit/index.js | 23 +++++++++++++++++ es/components/extraFile/commit/index.less | 5 ++++ es/components/extraFile/commit/index.xml | 4 +++ es/components/extraFile/commit/web.d.ts | 4 +-- es/components/extraFile/commit/web.js | 26 +++---------------- es/components/extraFile/commit/web.pc.d.ts | 4 +-- es/components/extraFile/commit/web.pc.js | 28 +++------------------ es/components/extraFile/upload/index.js | 8 +----- lib/components/extraFile/commit/index.js | 23 +++++++++++++++++ lib/components/extraFile/commit/index.less | 5 ++++ lib/components/extraFile/commit/index.xml | 4 +++ lib/components/extraFile/commit/web.d.ts | 4 +-- lib/components/extraFile/commit/web.js | 26 +++---------------- lib/components/extraFile/commit/web.pc.d.ts | 4 +-- lib/components/extraFile/commit/web.pc.js | 26 +++---------------- lib/components/extraFile/upload/index.js | 8 +----- src/components/extraFile/commit/index.xml | 2 +- 17 files changed, 83 insertions(+), 121 deletions(-) create mode 100644 es/components/extraFile/commit/index.less create mode 100644 es/components/extraFile/commit/index.xml create mode 100644 lib/components/extraFile/commit/index.less create mode 100644 lib/components/extraFile/commit/index.xml diff --git a/es/components/extraFile/commit/index.js b/es/components/extraFile/commit/index.js index d2c16d207..ec968ee3d 100644 --- a/es/components/extraFile/commit/index.js +++ b/es/components/extraFile/commit/index.js @@ -71,6 +71,29 @@ export default OakComponent({ await Promise.all(promises); } }, + async onSubmit() { + const { oakExecutable } = this.state; + const { beforeCommit, afterCommit, action } = this.props; + if (oakExecutable) { + if (beforeCommit) { + const beforeCommitResult = await beforeCommit(); + if (beforeCommitResult === false) { + return; + } + } + await this.execute(action || undefined); + await this.upload(); + if (afterCommit) { + afterCommit(); + } + } + else { + await this.upload(); + if (afterCommit) { + afterCommit(); + } + } + }, }, features: ['extraFile2'], }); diff --git a/es/components/extraFile/commit/index.less b/es/components/extraFile/commit/index.less new file mode 100644 index 000000000..ad732cb8a --- /dev/null +++ b/es/components/extraFile/commit/index.less @@ -0,0 +1,5 @@ +/** index.wxss **/ + +.btn { + display: flex; +} \ No newline at end of file diff --git a/es/components/extraFile/commit/index.xml b/es/components/extraFile/commit/index.xml new file mode 100644 index 000000000..88b9b09c9 --- /dev/null +++ b/es/components/extraFile/commit/index.xml @@ -0,0 +1,4 @@ + + + {{ executeText || t('common:submit') }} + \ No newline at end of file diff --git a/es/components/extraFile/commit/web.d.ts b/es/components/extraFile/commit/web.d.ts index b71bf1c1e..7c1c0c63c 100644 --- a/es/components/extraFile/commit/web.d.ts +++ b/es/components/extraFile/commit/web.d.ts @@ -10,8 +10,6 @@ export default function render(props: WebComponentProps Promise | boolean | undefined; - afterCommit?: () => void; }, { - upload: () => Promise; + onSubmit: () => Promise; }>): import("react/jsx-runtime").JSX.Element; diff --git a/es/components/extraFile/commit/web.js b/es/components/extraFile/commit/web.js index 31c49d3b0..fc1e51d2b 100644 --- a/es/components/extraFile/commit/web.js +++ b/es/components/extraFile/commit/web.js @@ -1,8 +1,8 @@ import { jsx as _jsx } from "react/jsx-runtime"; import { Button } from 'antd-mobile'; export default function render(props) { - const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps, action, beforeCommit, afterCommit, } = props.data; - const { t, upload, execute } = props.methods; + const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps, } = props.data; + const { t, onSubmit } = props.methods; const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable === false && ['uploaded'].includes(state)); @@ -18,25 +18,5 @@ export default function render(props) { text = t('upload'); } } - return (_jsx(Button, { type: type, size: size, block: block, disabled: disabled, onClick: async () => { - if (oakExecutable) { - if (beforeCommit) { - const beforeCommitResult = await beforeCommit(); - if (beforeCommitResult === false) { - return; - } - } - await execute(action || undefined); - await upload(); - if (afterCommit) { - afterCommit(); - } - } - else { - await upload(); - if (afterCommit) { - afterCommit(); - } - } - }, ...buttonProps, children: text })); + return (_jsx(Button, { type: type, size: size, block: block, disabled: disabled, onClick: onSubmit, ...buttonProps, children: text })); } diff --git a/es/components/extraFile/commit/web.pc.d.ts b/es/components/extraFile/commit/web.pc.d.ts index 8ffc49745..1c23ac7b1 100644 --- a/es/components/extraFile/commit/web.pc.d.ts +++ b/es/components/extraFile/commit/web.pc.d.ts @@ -10,8 +10,6 @@ export default function render(props: WebComponentProps void; - beforeCommit?: () => Promise | boolean; }, { - upload: () => Promise; + onSubmit: () => Promise; }>): import("react/jsx-runtime").JSX.Element; diff --git a/es/components/extraFile/commit/web.pc.js b/es/components/extraFile/commit/web.pc.js index c9cb8a5e6..79b24540f 100644 --- a/es/components/extraFile/commit/web.pc.js +++ b/es/components/extraFile/commit/web.pc.js @@ -1,8 +1,8 @@ import { jsx as _jsx } from "react/jsx-runtime"; import { Button } from 'antd'; export default function render(props) { - const { state, oakExecutable, oakExecuting, size, block, type, executeText, buttonProps = {}, action, afterCommit, beforeCommit, } = props.data; - const { t, upload, execute } = props.methods; + const { state, oakExecutable, oakExecuting, size, block, type, executeText, buttonProps = {}, } = props.data; + const { t, onSubmit } = props.methods; const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable !== true && ['uploaded'].includes(state)); @@ -18,27 +18,5 @@ export default function render(props) { text = t('upload'); } } - return (_jsx(Button, { - type: type, size: size, block: block, disabled: disabled, onClick: async () => { - if (oakExecutable) { - if (beforeCommit) { - const beforeCommitResult = await beforeCommit(); - if (beforeCommitResult === false) { - return; - } - } - await execute(action || undefined); - await upload(); - if (afterCommit) { - afterCommit(); - } - } - else { - await upload(); - if (afterCommit) { - afterCommit(); - } - } - }, ...buttonProps, children: text - })); + return (_jsx(Button, { type: type, size: size, block: block, disabled: disabled, onClick: onSubmit, ...buttonProps, children: text })); } diff --git a/es/components/extraFile/upload/index.js b/es/components/extraFile/upload/index.js index 359f1a206..44f6273b0 100644 --- a/es/components/extraFile/upload/index.js +++ b/es/components/extraFile/upload/index.js @@ -210,6 +210,7 @@ export default OakComponent({ const { errMsg, tempFiles } = await wx.chooseMessageFile({ count: selectCount, type: 'all', + ...(extension && extension.length > 0 ? { extension } : {}), }); if (errMsg !== 'chooseMessageFile:ok') { this.triggerEvent('onError', { @@ -257,19 +258,12 @@ export default OakComponent({ const { index } = event.currentTarget.dataset; const imageUrl = files[index].url; const urls = files?.filter((ele) => !!ele).map((ele) => ele.url); - const detail = { - all: files, - index, - urls, - current: imageUrl, - }; // 预览图片 if (!this.props.disablePreview) { const result = await wx.previewImage({ urls: urls, current: imageUrl, }); - this.triggerEvent('onPreview', detail); } }, getSort(index = 0) { diff --git a/lib/components/extraFile/commit/index.js b/lib/components/extraFile/commit/index.js index 11e735b3e..b088fc8cc 100644 --- a/lib/components/extraFile/commit/index.js +++ b/lib/components/extraFile/commit/index.js @@ -74,6 +74,29 @@ exports.default = OakComponent({ await Promise.all(promises); } }, + async onSubmit() { + const { oakExecutable } = this.state; + const { beforeCommit, afterCommit, action } = this.props; + if (oakExecutable) { + if (beforeCommit) { + const beforeCommitResult = await beforeCommit(); + if (beforeCommitResult === false) { + return; + } + } + await this.execute(action || undefined); + await this.upload(); + if (afterCommit) { + afterCommit(); + } + } + else { + await this.upload(); + if (afterCommit) { + afterCommit(); + } + } + }, }, features: ['extraFile2'], }); diff --git a/lib/components/extraFile/commit/index.less b/lib/components/extraFile/commit/index.less new file mode 100644 index 000000000..ad732cb8a --- /dev/null +++ b/lib/components/extraFile/commit/index.less @@ -0,0 +1,5 @@ +/** index.wxss **/ + +.btn { + display: flex; +} \ No newline at end of file diff --git a/lib/components/extraFile/commit/index.xml b/lib/components/extraFile/commit/index.xml new file mode 100644 index 000000000..88b9b09c9 --- /dev/null +++ b/lib/components/extraFile/commit/index.xml @@ -0,0 +1,4 @@ + + + {{ executeText || t('common:submit') }} + \ No newline at end of file diff --git a/lib/components/extraFile/commit/web.d.ts b/lib/components/extraFile/commit/web.d.ts index b71bf1c1e..7c1c0c63c 100644 --- a/lib/components/extraFile/commit/web.d.ts +++ b/lib/components/extraFile/commit/web.d.ts @@ -10,8 +10,6 @@ export default function render(props: WebComponentProps Promise | boolean | undefined; - afterCommit?: () => void; }, { - upload: () => Promise; + onSubmit: () => Promise; }>): import("react/jsx-runtime").JSX.Element; diff --git a/lib/components/extraFile/commit/web.js b/lib/components/extraFile/commit/web.js index 086f096b6..e3c6480f0 100644 --- a/lib/components/extraFile/commit/web.js +++ b/lib/components/extraFile/commit/web.js @@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const antd_mobile_1 = require("antd-mobile"); function render(props) { - const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps, action, beforeCommit, afterCommit, } = props.data; - const { t, upload, execute } = props.methods; + const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps, } = props.data; + const { t, onSubmit } = props.methods; const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable === false && ['uploaded'].includes(state)); @@ -20,26 +20,6 @@ function render(props) { text = t('upload'); } } - return ((0, jsx_runtime_1.jsx)(antd_mobile_1.Button, { type: type, size: size, block: block, disabled: disabled, onClick: async () => { - if (oakExecutable) { - if (beforeCommit) { - const beforeCommitResult = await beforeCommit(); - if (beforeCommitResult === false) { - return; - } - } - await execute(action || undefined); - await upload(); - if (afterCommit) { - afterCommit(); - } - } - else { - await upload(); - if (afterCommit) { - afterCommit(); - } - } - }, ...buttonProps, children: text })); + return ((0, jsx_runtime_1.jsx)(antd_mobile_1.Button, { type: type, size: size, block: block, disabled: disabled, onClick: onSubmit, ...buttonProps, children: text })); } exports.default = render; diff --git a/lib/components/extraFile/commit/web.pc.d.ts b/lib/components/extraFile/commit/web.pc.d.ts index 8ffc49745..1c23ac7b1 100644 --- a/lib/components/extraFile/commit/web.pc.d.ts +++ b/lib/components/extraFile/commit/web.pc.d.ts @@ -10,8 +10,6 @@ export default function render(props: WebComponentProps void; - beforeCommit?: () => Promise | boolean; }, { - upload: () => Promise; + onSubmit: () => Promise; }>): import("react/jsx-runtime").JSX.Element; diff --git a/lib/components/extraFile/commit/web.pc.js b/lib/components/extraFile/commit/web.pc.js index c12779171..cc55543c1 100644 --- a/lib/components/extraFile/commit/web.pc.js +++ b/lib/components/extraFile/commit/web.pc.js @@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const antd_1 = require("antd"); function render(props) { - const { state, oakExecutable, oakExecuting, size, block, type, executeText, buttonProps = {}, action, afterCommit, beforeCommit, } = props.data; - const { t, upload, execute } = props.methods; + const { state, oakExecutable, oakExecuting, size, block, type, executeText, buttonProps = {}, } = props.data; + const { t, onSubmit } = props.methods; const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable !== true && ['uploaded'].includes(state)); @@ -20,26 +20,6 @@ function render(props) { text = t('upload'); } } - return ((0, jsx_runtime_1.jsx)(antd_1.Button, { type: type, size: size, block: block, disabled: disabled, onClick: async () => { - if (oakExecutable) { - if (beforeCommit) { - const beforeCommitResult = await beforeCommit(); - if (beforeCommitResult === false) { - return; - } - } - await execute(action || undefined); - await upload(); - if (afterCommit) { - afterCommit(); - } - } - else { - await upload(); - if (afterCommit) { - afterCommit(); - } - } - }, ...buttonProps, children: text })); + return ((0, jsx_runtime_1.jsx)(antd_1.Button, { type: type, size: size, block: block, disabled: disabled, onClick: onSubmit, ...buttonProps, children: text })); } exports.default = render; diff --git a/lib/components/extraFile/upload/index.js b/lib/components/extraFile/upload/index.js index 07b6955b8..ca9311c2a 100644 --- a/lib/components/extraFile/upload/index.js +++ b/lib/components/extraFile/upload/index.js @@ -212,6 +212,7 @@ exports.default = OakComponent({ const { errMsg, tempFiles } = await wx.chooseMessageFile({ count: selectCount, type: 'all', + ...(extension && extension.length > 0 ? { extension } : {}), }); if (errMsg !== 'chooseMessageFile:ok') { this.triggerEvent('onError', { @@ -259,19 +260,12 @@ exports.default = OakComponent({ const { index } = event.currentTarget.dataset; const imageUrl = files[index].url; const urls = files?.filter((ele) => !!ele).map((ele) => ele.url); - const detail = { - all: files, - index, - urls, - current: imageUrl, - }; // 预览图片 if (!this.props.disablePreview) { const result = await wx.previewImage({ urls: urls, current: imageUrl, }); - this.triggerEvent('onPreview', detail); } }, getSort(index = 0) { diff --git a/src/components/extraFile/commit/index.xml b/src/components/extraFile/commit/index.xml index 2c09052c5..88b9b09c9 100644 --- a/src/components/extraFile/commit/index.xml +++ b/src/components/extraFile/commit/index.xml @@ -1,4 +1,4 @@ - + {{ executeText || t('common:submit') }} \ No newline at end of file