From 16791483c8d7f1e88f26f4c8f0c511917975a3a2 Mon Sep 17 00:00:00 2001 From: Xc Date: Tue, 17 May 2022 23:24:35 +0800 Subject: [PATCH] file-selector --- src/utils/extraFile.ts | 2 +- .../components/Func/file-selector/index.less | 8 +- .../components/Func/file-selector/index.ts | 91 +++++++++++++++++-- .../components/Func/file-selector/index.wxml | 6 +- .../components/extraFile/upsert/index.less | 5 +- wechatMp/components/extraFile/upsert/index.ts | 4 +- .../components/extraFile/upsert/index.wxml | 2 +- 7 files changed, 100 insertions(+), 18 deletions(-) diff --git a/src/utils/extraFile.ts b/src/utils/extraFile.ts index c2df318bd..4d2020358 100644 --- a/src/utils/extraFile.ts +++ b/src/utils/extraFile.ts @@ -6,7 +6,7 @@ export function composeFileUrl(extraFile: Pick { diff --git a/wechatMp/components/Func/file-selector/index.less b/wechatMp/components/Func/file-selector/index.less index 286ba70df..b47181326 100644 --- a/wechatMp/components/Func/file-selector/index.less +++ b/wechatMp/components/Func/file-selector/index.less @@ -4,12 +4,14 @@ display: flex; flex-direction: row; flex-wrap: wrap; + padding: 10rpx; } .default-item { - width: 200rpx; - height: 300rpx; - border: 1ch solid black; + width: 160rpx; + height: 220rpx; + border: 1px solid black; + border-color: @primary-color; } .insert-btn { diff --git a/wechatMp/components/Func/file-selector/index.ts b/wechatMp/components/Func/file-selector/index.ts index b0c43fc04..9a3694741 100644 --- a/wechatMp/components/Func/file-selector/index.ts +++ b/wechatMp/components/Func/file-selector/index.ts @@ -1,22 +1,93 @@ +import { WechatMpFileCarrier } from "oak-frontend-base"; + Component({ externalClasses: ['item-container', 'item'], properties: { + oakUpdateData: Object, oakValue: Array, - maxCount: Number, + oakParent: String, + oakPath: String, + maxNumber: { + type: Number, + value: 100, + }, + selectCount: { + type: Number, + value: 1, + }, + sourceType: { + type: Array, + value: ['album', 'camera'], + }, + mediaType: { + type: Array, + value: ['image'], + }, disableInsert: Boolean, }, methods: { - onClick(touch: WechatMiniprogram.Touch) { + async onAdd() { + const { selectCount, mediaType, sourceType, oakUpdateData } = this.data; + try { + const { errMsg, tempFiles } = await wx.chooseMedia({ + count: selectCount, + mediaType, + sourceType, + }); + if (errMsg !== 'chooseMedia:ok') { + this.setData({ + oakError: { + level: 'warning', + msg: errMsg, + }, + }); + } + else { + const { globalData: { features } } = getApp(); + const { oakFullpath } = this.data; + for (const file of tempFiles) { + await features.runningNode.addNode({ + parent: oakFullpath, + fileCarrier: new WechatMpFileCarrier(file), + updateData: oakUpdateData, + }); + } + } + } + catch (err: any) { + if (err.errMsg !== 'chooseMedia:fail cancel') { + this.setData({ + oakError: { + level: 'error', + msg: err.errMsg, + }, + }); + } + } }, - checkAllowInsert(value?: Array, count?: number) { - const count2 = count || this.data.maxCount; + checkAllowInsert(value?: Array, num?: number) { + const number2 = num || this.data.maxNumber; const value2 = value || this.data.oakValue; - if (typeof count2 === 'number' && value2?.length >= count2) { + if (typeof number2 === 'number' && value2?.length >= number2) { this.setData({ disableInsert: true, }); } + }, + async setFullpath(oakParent: string) { + const { globalData: { features }} = getApp(); + console.log(this.data); + if (oakParent) { + const oakFullpath = `${oakParent}.${this.data.oakPath}`; + await features.runningNode.createNode({ + path: this.data.oakPath, + parent: oakParent, + }); + this.setData({ + oakFullpath, + }); + } } }, @@ -24,14 +95,20 @@ Component({ oakValue: function (oakValue) { this.checkAllowInsert(oakValue); }, - maxCount: function (maxCount) { - this.checkAllowInsert(undefined, maxCount); + maxNumber: function (maxNumber) { + this.checkAllowInsert(undefined, maxNumber); + }, + oakParent: async function (oakParent) { + await this.setFullpath(oakParent); } }, lifetimes: { ready() { this.checkAllowInsert(); + if (this.data.oakParent) { + this.setFullpath(this.data.oakParent); + } } } }); diff --git a/wechatMp/components/Func/file-selector/index.wxml b/wechatMp/components/Func/file-selector/index.wxml index 54ec4c10d..1835ee03e 100644 --- a/wechatMp/components/Func/file-selector/index.wxml +++ b/wechatMp/components/Func/file-selector/index.wxml @@ -1,8 +1,8 @@ - + - - > + + \ No newline at end of file diff --git a/wechatMp/components/extraFile/upsert/index.less b/wechatMp/components/extraFile/upsert/index.less index 3c7738f92..72b6796c7 100644 --- a/wechatMp/components/extraFile/upsert/index.less +++ b/wechatMp/components/extraFile/upsert/index.less @@ -1,5 +1,6 @@ /** index.wxss **/ -.container { - display: block; +.img { + max-width: 100%; + max-height: 100%; } diff --git a/wechatMp/components/extraFile/upsert/index.ts b/wechatMp/components/extraFile/upsert/index.ts index e4272faf4..4cf668ed2 100644 --- a/wechatMp/components/extraFile/upsert/index.ts +++ b/wechatMp/components/extraFile/upsert/index.ts @@ -1,12 +1,14 @@ import assert from 'assert'; +import { EntityDict } from 'oak-app-domain'; import { WechatMpFileCarrier } from 'oak-frontend-base'; import { composeFileUrl } from '../../../../src/utils/extraFile'; OakComponent({ entity: 'extraFile', formData: async (_rows, _features, _fileCarrier) => { if (_fileCarrier) { + const file = (>_fileCarrier).getFile(); return { - src: '11', + src: file.tempFilePath || file.thumbTempFilePath, }; } else { diff --git a/wechatMp/components/extraFile/upsert/index.wxml b/wechatMp/components/extraFile/upsert/index.wxml index 1e080777f..2d1cadb45 100644 --- a/wechatMp/components/extraFile/upsert/index.wxml +++ b/wechatMp/components/extraFile/upsert/index.wxml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file