From 9f7678230aaadf0a3913be325c0512fb92ebdeff Mon Sep 17 00:00:00 2001 From: linju Date: Fri, 2 Sep 2022 15:49:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=97=A7=E7=89=88uni-ui?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uni-data-checkbox/changelog.md | 2 - .../components/uni-data-checkbox/clientdb.js | 316 +++++ .../uni-data-checkbox/uni-data-checkbox.vue | 48 +- uni_modules/uni-data-checkbox/package.json | 2 +- uni_modules/uni-easyinput/changelog.md | 10 - .../uni-easyinput/uni-easyinput.vue | 324 ++---- uni_modules/uni-easyinput/package.json | 2 +- uni_modules/uni-forms/changelog.md | 30 - .../uni-forms-item/uni-forms-item.vue | 1030 ++++++++--------- .../components/uni-forms/uni-forms.vue | 463 ++++---- uni_modules/uni-forms/package.json | 14 +- 11 files changed, 1169 insertions(+), 1072 deletions(-) create mode 100644 uni_modules/uni-data-checkbox/components/uni-data-checkbox/clientdb.js diff --git a/uni_modules/uni-data-checkbox/changelog.md b/uni_modules/uni-data-checkbox/changelog.md index dbc517a3..d8f420b9 100644 --- a/uni_modules/uni-data-checkbox/changelog.md +++ b/uni_modules/uni-data-checkbox/changelog.md @@ -1,5 +1,3 @@ -## 1.0.2(2022-06-30) -- 优化 在 uni-forms 中的依赖注入方式 ## 1.0.1(2022-02-07) - 修复 multiple 为 true 时,v-model 的值为 null 报错的 bug ## 1.0.0(2021-11-19) diff --git a/uni_modules/uni-data-checkbox/components/uni-data-checkbox/clientdb.js b/uni_modules/uni-data-checkbox/components/uni-data-checkbox/clientdb.js new file mode 100644 index 00000000..7079ade6 --- /dev/null +++ b/uni_modules/uni-data-checkbox/components/uni-data-checkbox/clientdb.js @@ -0,0 +1,316 @@ + +const events = { + load: 'load', + error: 'error' +} +const pageMode = { + add: 'add', + replace: 'replace' +} + +const attrs = [ + 'pageCurrent', + 'pageSize', + 'collection', + 'action', + 'field', + 'getcount', + 'orderby', + 'where' +] + +export default { + data() { + return { + loading: false, + listData: this.getone ? {} : [], + paginationInternal: { + current: this.pageCurrent, + size: this.pageSize, + count: 0 + }, + errorMessage: '' + } + }, + created() { + let db = null; + let dbCmd = null; + + if(this.collection){ + this.db = uniCloud.database(); + this.dbCmd = this.db.command; + } + + this._isEnded = false + + this.$watch(() => { + var al = [] + attrs.forEach(key => { + al.push(this[key]) + }) + return al + }, (newValue, oldValue) => { + this.paginationInternal.pageSize = this.pageSize + + let needReset = false + for (let i = 2; i < newValue.length; i++) { + if (newValue[i] != oldValue[i]) { + needReset = true + break + } + } + if (needReset) { + this.clear() + this.reset() + } + if (newValue[0] != oldValue[0]) { + this.paginationInternal.current = this.pageCurrent + } + + this._execLoadData() + }) + + // #ifdef H5 + if (process.env.NODE_ENV === 'development') { + this._debugDataList = [] + if (!window.unidev) { + window.unidev = { + clientDB: { + data: [] + } + } + } + unidev.clientDB.data.push(this._debugDataList) + } + // #endif + + // #ifdef MP-TOUTIAO + let changeName + let events = this.$scope.dataset.eventOpts + for (var i = 0; i < events.length; i++) { + let event = events[i] + if (event[0].includes('^load')) { + changeName = event[1][0][0] + } + } + if (changeName) { + let parent = this.$parent + let maxDepth = 16 + this._changeDataFunction = null + while (parent && maxDepth > 0) { + let fun = parent[changeName] + if (fun && typeof fun === 'function') { + this._changeDataFunction = fun + maxDepth = 0 + break + } + parent = parent.$parent + maxDepth--; + } + } + // #endif + + // if (!this.manual) { + // this.loadData() + // } + }, + // #ifdef H5 + beforeDestroy() { + if (process.env.NODE_ENV === 'development' && window.unidev) { + var cd = this._debugDataList + var dl = unidev.clientDB.data + for (var i = dl.length - 1; i >= 0; i--) { + if (dl[i] === cd) { + dl.splice(i, 1) + break + } + } + } + }, + // #endif + methods: { + loadData(args1, args2) { + let callback = null + if (typeof args1 === 'object') { + if (args1.clear) { + this.clear() + this.reset() + } + if (args1.current !== undefined) { + this.paginationInternal.current = args1.current + } + if (typeof args2 === 'function') { + callback = args2 + } + } else if (typeof args1 === 'function') { + callback = args1 + } + + this._execLoadData(callback) + }, + loadMore() { + if (this._isEnded) { + return + } + this._execLoadData() + }, + refresh() { + this.clear() + this._execLoadData() + }, + clear() { + this._isEnded = false + this.listData = [] + }, + reset() { + this.paginationInternal.current = 1 + }, + remove(id, { + action, + callback, + confirmTitle, + confirmContent + } = {}) { + if (!id || !id.length) { + return + } + uni.showModal({ + title: confirmTitle || '提示', + content: confirmContent || '是否删除该数据', + showCancel: true, + success: (res) => { + if (!res.confirm) { + return + } + this._execRemove(id, action, callback) + } + }) + }, + _execLoadData(callback) { + if (this.loading) { + return + } + this.loading = true + this.errorMessage = '' + + this._getExec().then((res) => { + this.loading = false + const { + data, + count + } = res.result + this._isEnded = data.length < this.pageSize + + callback && callback(data, this._isEnded) + this._dispatchEvent(events.load, data) + + if (this.getone) { + this.listData = data.length ? data[0] : undefined + } else if (this.pageData === pageMode.add) { + this.listData.push(...data) + if (this.listData.length) { + this.paginationInternal.current++ + } + } else if (this.pageData === pageMode.replace) { + this.listData = data + this.paginationInternal.count = count + } + + // #ifdef H5 + if (process.env.NODE_ENV === 'development') { + this._debugDataList.length = 0 + this._debugDataList.push(...JSON.parse(JSON.stringify(this.listData))) + } + // #endif + }).catch((err) => { + this.loading = false + this.errorMessage = err + callback && callback() + this.$emit(events.error, err) + }) + }, + _getExec() { + let exec = this.db + if (this.action) { + exec = exec.action(this.action) + } + + exec = exec.collection(this.collection) + + if (!(!this.where || !Object.keys(this.where).length)) { + exec = exec.where(this.where) + } + if (this.field) { + exec = exec.field(this.field) + } + if (this.orderby) { + exec = exec.orderBy(this.orderby) + } + + const { + current, + size + } = this.paginationInternal + exec = exec.skip(size * (current - 1)).limit(size).get({ + getCount: this.getcount + }) + + return exec + }, + _execRemove(id, action, callback) { + if (!this.collection || !id) { + return + } + + const ids = Array.isArray(id) ? id : [id] + if (!ids.length) { + return + } + + uni.showLoading({ + mask: true + }) + + let exec = this.db + if (action) { + exec = exec.action(action) + } + + exec.collection(this.collection).where({ + _id: dbCmd.in(ids) + }).remove().then((res) => { + callback && callback(res.result) + if (this.pageData === pageMode.replace) { + this.refresh() + } else { + this.removeData(ids) + } + }).catch((err) => { + uni.showModal({ + content: err.message, + showCancel: false + }) + }).finally(() => { + uni.hideLoading() + }) + }, + removeData(ids) { + let il = ids.slice(0) + let dl = this.listData + for (let i = dl.length - 1; i >= 0; i--) { + let index = il.indexOf(dl[i]._id) + if (index >= 0) { + dl.splice(i, 1) + il.splice(index, 1) + } + } + }, + _dispatchEvent(type, data) { + if (this._changeDataFunction) { + this._changeDataFunction(data, this._isEnded) + } else { + this.$emit(type, data, this._isEnded) + } + } + } +} diff --git a/uni_modules/uni-data-checkbox/components/uni-data-checkbox/uni-data-checkbox.vue b/uni_modules/uni-data-checkbox/components/uni-data-checkbox/uni-data-checkbox.vue index eb3ae3f8..300cb5fe 100644 --- a/uni_modules/uni-data-checkbox/components/uni-data-checkbox/uni-data-checkbox.vue +++ b/uni_modules/uni-data-checkbox/components/uni-data-checkbox/uni-data-checkbox.vue @@ -155,17 +155,17 @@ value(newVal) { this.dataList = this.getDataList(newVal) // fix by mehaotian is_reset 在 uni-forms 中定义 - // if(!this.is_reset){ - // this.is_reset = false - // this.formItem && this.formItem.setValue(newVal) - // } + if(!this.is_reset){ + this.is_reset = false + this.formItem && this.formItem.setValue(newVal) + } }, modelValue(newVal) { this.dataList = this.getDataList(newVal); - // if(!this.is_reset){ - // this.is_reset = false - // this.formItem && this.formItem.setValue(newVal) - // } + if(!this.is_reset){ + this.is_reset = false + this.formItem && this.formItem.setValue(newVal) + } } }, data() { @@ -193,22 +193,22 @@ } }, created() { - // this.form = this.getForm('uniForms') - // this.formItem = this.getForm('uniFormsItem') + this.form = this.getForm('uniForms') + this.formItem = this.getForm('uniFormsItem') // this.formItem && this.formItem.setValue(this.value) - // if (this.formItem) { - // this.isTop = 6 - // if (this.formItem.name) { - // // 如果存在name添加默认值,否则formData 中不存在这个字段不校验 - // if(!this.is_reset){ - // this.is_reset = false - // this.formItem.setValue(this.dataValue) - // } - // this.rename = this.formItem.name - // this.form.inputChildrens.push(this) - // } - // } + if (this.formItem) { + this.isTop = 6 + if (this.formItem.name) { + // 如果存在name添加默认值,否则formData 中不存在这个字段不校验 + if(!this.is_reset){ + this.is_reset = false + this.formItem.setValue(this.dataValue) + } + this.rename = this.formItem.name + this.form.inputChildrens.push(this) + } + } if (this.localdata && this.localdata.length !== 0) { this.isLocal = true @@ -273,7 +273,7 @@ } } } - // this.formItem && this.formItem.setValue(detail.value) + this.formItem && this.formItem.setValue(detail.value) // TODO 兼容 vue2 this.$emit('input', detail.value); // // TOTO 兼容 vue3 @@ -375,7 +375,7 @@ selectedArr.push(item[this.map.value]) } }) - return this.dataValue.length > 0 ? this.dataValue : selectedArr + return this.dataValue && this.dataValue.length > 0 ? this.dataValue : selectedArr }, /** diff --git a/uni_modules/uni-data-checkbox/package.json b/uni_modules/uni-data-checkbox/package.json index 51470a95..64131e75 100644 --- a/uni_modules/uni-data-checkbox/package.json +++ b/uni_modules/uni-data-checkbox/package.json @@ -1,7 +1,7 @@ { "id": "uni-data-checkbox", "displayName": "uni-data-checkbox 数据选择器", - "version": "1.0.2", + "version": "1.0.1", "description": "通过数据驱动的单选框和复选框", "keywords": [ "uni-ui", diff --git a/uni_modules/uni-easyinput/changelog.md b/uni_modules/uni-easyinput/changelog.md index 1e8c6f91..6998f994 100644 --- a/uni_modules/uni-easyinput/changelog.md +++ b/uni_modules/uni-easyinput/changelog.md @@ -1,13 +1,3 @@ -## 1.1.0(2022-06-30) -- 新增 在 uni-forms 1.4.0 中使用可以在 blur 时校验内容 -- 新增 clear 事件,点击右侧叉号图标触发 -- 新增 change 事件 ,仅在输入框失去焦点或用户按下回车时触发 -- 优化 组件样式,组件获取焦点时高亮显示,图标颜色调整等 -- -## 1.0.5(2022-06-07) -- 优化 clearable 显示策略 -## 1.0.4(2022-06-07) -- 优化 clearable 显示策略 ## 1.0.3(2022-05-20) - 修复 关闭图标某些情况下无法取消的bug ## 1.0.2(2022-04-12) diff --git a/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue b/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue index d129ce15..c59736bf 100644 --- a/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue +++ b/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue @@ -1,34 +1,29 @@