From 84ce1d2ef0b761ee9ae906f14f624a91ad990f55 Mon Sep 17 00:00:00 2001 From: linju Date: Tue, 20 Sep 2022 20:03:44 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=9B=B4=E6=96=B0=E8=A1=A8=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86clientDB?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=B2=A1=E6=9C=89=E6=9D=83=E9=99=90=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uni-calendar/changelog.md | 32 +- .../uni-calendar/uni-calendar-item.vue | 15 +- .../components/uni-calendar/uni-calendar.vue | 23 +- .../components/uni-calendar/util.js | 28 +- uni_modules/uni-calendar/package.json | 171 ++- uni_modules/uni-data-picker/changelog.md | 114 +- .../components/uni-data-picker/keypress.js | 90 +- .../uni-data-picker/uni-data-picker.vue | 55 +- .../uni-data-pickerview/uni-data-picker.js | 1126 ++++++++--------- .../uni-data-pickerview.vue | 16 +- uni_modules/uni-data-picker/package.json | 178 ++- uni_modules/uni-data-picker/readme.md | 42 +- uni_modules/uni-data-select/changelog.md | 22 + .../uni-data-select/uni-data-select.vue | 440 +++++++ uni_modules/uni-data-select/package.json | 85 ++ uni_modules/uni-data-select/readme.md | 8 + uni_modules/uni-datetime-picker/changelog.md | 188 +-- .../uni-datetime-picker/calendar-item.vue | 68 +- .../uni-datetime-picker/calendar.vue | 72 +- .../uni-datetime-picker/i18n/en.json | 15 +- .../uni-datetime-picker/i18n/zh-Hans.json | 21 +- .../uni-datetime-picker/i18n/zh-Hant.json | 41 +- .../uni-datetime-picker/time-picker.vue | 9 +- .../uni-datetime-picker.vue | 158 ++- uni_modules/uni-datetime-picker/package.json | 177 ++- uni_modules/uni-easyinput/changelog.md | 2 + .../uni-easyinput/uni-easyinput.vue | 17 +- uni_modules/uni-easyinput/package.json | 11 +- uni_modules/uni-fab/changelog.md | 4 + .../uni-fab/components/uni-fab/uni-fab.vue | 16 +- uni_modules/uni-fab/package.json | 11 +- uni_modules/uni-fav/changelog.md | 30 +- .../uni-fav/components/uni-fav/uni-fav.vue | 79 +- uni_modules/uni-fav/package.json | 176 +-- uni_modules/uni-feedback/changelog.md | 4 + uni_modules/uni-feedback/package.json | 8 +- .../pages/opendb-feedback/list.vue | 2 +- uni_modules/uni-file-picker/changelog.md | 108 +- .../uni-file-picker/uni-file-picker.vue | 18 +- .../components/uni-file-picker/utils.js | 218 ++-- uni_modules/uni-file-picker/package.json | 172 +-- uni_modules/uni-file-picker/readme.md | 18 +- uni_modules/uni-goods-nav/changelog.md | 28 +- .../uni-goods-nav/uni-goods-nav.vue | 11 +- uni_modules/uni-goods-nav/package.json | 172 +-- uni_modules/uni-group/changelog.md | 18 +- .../components/uni-group/uni-group.vue | 26 +- uni_modules/uni-group/package.json | 172 +-- uni_modules/uni-group/readme.md | 10 +- uni_modules/uni-id-pages/changelog.md | 12 + uni_modules/uni-id-pages/common/common.js | 4 +- .../uni-id-pages/common/login-page.scss | 45 +- uni_modules/uni-id-pages/package.json | 2 +- .../pages/login/login-withoutpwd.vue | 6 +- .../pages/retrieve/retrieve-by-email.vue | 14 +- .../uni-id-pages/pages/retrieve/retrieve.vue | 12 +- .../pages/userinfo/change_pwd/change_pwd.vue | 56 +- .../uni-id-pages/pages/userinfo/userinfo.vue | 2 +- .../cloudfunctions/uni-id-co/package.json | 2 +- .../uniCloud/database/uni-id-log.schema.json | 8 +- .../database/uni-id-permissions.schema.json | 15 +- .../database/uni-id-roles.schema.json | 30 +- .../database/uni-id-users.schema.json | 860 ++++++------- uni_modules/uni-id/changelog.md | 22 + uni_modules/uni-id/package.json | 17 +- .../cloudfunctions/common/uni-id/LICENSE.md | 201 +++ .../cloudfunctions/common/uni-id/index.js | 1 + .../cloudfunctions/common/uni-id/package.json | 16 + uni_modules/uni-nav-bar/changelog.md | 78 +- .../components/uni-nav-bar/uni-nav-bar.vue | 13 +- uni_modules/uni-nav-bar/package.json | 176 +-- uni_modules/uni-notice-bar/changelog.md | 28 +- .../uni-notice-bar/uni-notice-bar.vue | 71 +- uni_modules/uni-notice-bar/package.json | 175 ++- uni_modules/uni-pagination/changelog.md | 7 + .../components/uni-pagination/i18n/en.json | 3 +- .../components/uni-pagination/i18n/es.json | 3 +- .../components/uni-pagination/i18n/fr.json | 3 +- .../uni-pagination/i18n/zh-Hans.json | 3 +- .../uni-pagination/i18n/zh-Hant.json | 3 +- .../uni-pagination/uni-pagination.vue | 90 +- uni_modules/uni-pagination/package.json | 11 +- uni_modules/uni-pagination/readme.md | 4 +- uni_modules/uni-rate/changelog.md | 42 +- .../uni-rate/components/uni-rate/uni-rate.vue | 2 +- uni_modules/uni-rate/package.json | 176 +-- uni_modules/uni-rate/readme.md | 20 +- uni_modules/uni-scss/manifest.json | 95 -- uni_modules/uni-search-bar/changelog.md | 54 +- .../uni-search-bar/uni-search-bar.vue | 97 +- uni_modules/uni-search-bar/package.json | 174 +-- uni_modules/uni-search-bar/readme.md | 28 +- uni_modules/uni-section/changelog.md | 2 + .../components/uni-section/uni-section.vue | 167 +++ uni_modules/uni-section/package.json | 87 ++ uni_modules/uni-section/readme.md | 8 + uni_modules/uni-swipe-action/changelog.md | 20 +- .../uni-swipe-action-item/bindingx.js | 2 + .../components/uni-swipe-action-item/isPC.js | 2 +- .../uni-swipe-action-item/mpalipay.js | 82 +- .../uni-swipe-action-item/mpother.js | 80 +- .../components/uni-swipe-action-item/mpwxs.js | 19 +- .../uni-swipe-action-item/render.js | 27 +- .../uni-swipe-action-item.vue | 191 ++- .../components/uni-swipe-action-item/wx.wxs | 2 +- uni_modules/uni-swipe-action/package.json | 170 +-- uni_modules/uni-swipe-action/readme.md | 2 +- uni_modules/uni-table/changelog.md | 38 +- .../components/uni-th/filter-dropdown.vue | 1006 +++++++-------- .../uni-table/components/uni-th/uni-th.vue | 39 +- uni_modules/uni-table/i18n/en.json | 9 + uni_modules/uni-table/i18n/es.json | 9 + uni_modules/uni-table/i18n/fr.json | 9 + uni_modules/uni-table/i18n/index.js | 12 + uni_modules/uni-table/i18n/zh-Hans.json | 9 + uni_modules/uni-table/i18n/zh-Hant.json | 9 + uni_modules/uni-table/package.json | 170 +-- uni_modules/uni-title/changelog.md | 12 +- .../components/uni-title/uni-title.vue | 8 +- uni_modules/uni-title/package.json | 174 +-- uni_modules/uni-title/readme.md | 26 +- uni_modules/uni-tooltip/changelog.md | 10 + .../components/uni-tooltip/uni-tooltip.vue | 68 + uni_modules/uni-tooltip/package.json | 83 ++ uni_modules/uni-tooltip/readme.md | 8 + uni_modules/uni-ui/changelog.md | 145 ++- uni_modules/uni-ui/package.json | 255 ++-- uni_modules/uni-ui/readme.md | 493 ++++---- .../uni-upgrade-center-app/changelog.md | 53 +- .../uni-upgrade-center-app/package.json | 14 +- .../pages/upgrade-popup.vue | 93 +- uni_modules/uni-upgrade-center-app/readme.md | 237 ++-- .../uniCloud/cloudfunctions/temp.png | Bin 0 -> 7644 bytes .../utils/call-check-version.js | 18 +- .../utils/check-update.js | 7 +- 135 files changed, 6419 insertions(+), 4662 deletions(-) create mode 100644 uni_modules/uni-data-select/changelog.md create mode 100644 uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue create mode 100644 uni_modules/uni-data-select/package.json create mode 100644 uni_modules/uni-data-select/readme.md create mode 100644 uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/LICENSE.md create mode 100644 uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/index.js create mode 100644 uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/package.json delete mode 100644 uni_modules/uni-scss/manifest.json create mode 100644 uni_modules/uni-section/changelog.md create mode 100644 uni_modules/uni-section/components/uni-section/uni-section.vue create mode 100644 uni_modules/uni-section/package.json create mode 100644 uni_modules/uni-section/readme.md create mode 100644 uni_modules/uni-table/i18n/en.json create mode 100644 uni_modules/uni-table/i18n/es.json create mode 100644 uni_modules/uni-table/i18n/fr.json create mode 100644 uni_modules/uni-table/i18n/index.js create mode 100644 uni_modules/uni-table/i18n/zh-Hans.json create mode 100644 uni_modules/uni-table/i18n/zh-Hant.json create mode 100644 uni_modules/uni-tooltip/changelog.md create mode 100644 uni_modules/uni-tooltip/components/uni-tooltip/uni-tooltip.vue create mode 100644 uni_modules/uni-tooltip/package.json create mode 100644 uni_modules/uni-tooltip/readme.md create mode 100644 uni_modules/uni-upgrade-center-app/uniCloud/cloudfunctions/temp.png diff --git a/uni_modules/uni-calendar/changelog.md b/uni_modules/uni-calendar/changelog.md index 0a62d48..0160b69 100644 --- a/uni_modules/uni-calendar/changelog.md +++ b/uni_modules/uni-calendar/changelog.md @@ -1,12 +1,20 @@ -## 1.4.3(2021-09-22) -- 修复 startDate、 endDate 属性失效的 bug -## 1.4.2(2021-08-24) -- 新增 支持国际化 -## 1.4.1(2021-08-05) -- 修复 弹出层被 tabbar 遮盖 bug -## 1.4.0(2021-07-30) -- 组件兼容 vue3,如何创建vue3项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834) -## 1.3.16(2021-05-12) -- 新增 组件示例地址 -## 1.3.15(2021-02-04) -- 调整为uni_modules目录规范 +## 1.4.7(2022-09-16) +- 可以使用 uni-scss 控制主题色 +## 1.4.6(2022-09-08) +- fix: 表头年月切换,导致改变当前日期为选择月1号,且未触发change事件 +## 1.4.5(2022-02-25) +- 修复 条件编译 nvue 不支持的 css 样式 +## 1.4.4(2022-02-25) +- 修复 条件编译 nvue 不支持的 css 样式 +## 1.4.3(2021-09-22) +- 修复 startDate、 endDate 属性失效的 bug +## 1.4.2(2021-08-24) +- 新增 支持国际化 +## 1.4.1(2021-08-05) +- 修复 弹出层被 tabbar 遮盖 bug +## 1.4.0(2021-07-30) +- 组件兼容 vue3,如何创建vue3项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834) +## 1.3.16(2021-05-12) +- 新增 组件示例地址 +## 1.3.15(2021-02-04) +- 调整为uni_modules目录规范 diff --git a/uni_modules/uni-calendar/components/uni-calendar/uni-calendar-item.vue b/uni_modules/uni-calendar/components/uni-calendar/uni-calendar-item.vue index cd5863d..d29ead5 100644 --- a/uni_modules/uni-calendar/components/uni-calendar/uni-calendar-item.vue +++ b/uni_modules/uni-calendar/components/uni-calendar/uni-calendar-item.vue @@ -96,6 +96,13 @@ diff --git a/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-picker.js b/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-picker.js index 555d2c5..c12fd54 100644 --- a/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-picker.js +++ b/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-picker.js @@ -1,563 +1,563 @@ -export default { - props: { - localdata: { - type: [Array, Object], - default () { - return [] - } - }, - spaceInfo: { - type: Object, - default () { - return {} - } - }, - collection: { - type: String, - default: '' - }, - action: { - type: String, - default: '' - }, - field: { - type: String, - default: '' - }, - orderby: { - type: String, - default: '' - }, - where: { - type: [String, Object], - default: '' - }, - pageData: { - type: String, - default: 'add' - }, - pageCurrent: { - type: Number, - default: 1 - }, - pageSize: { - type: Number, - default: 20 - }, - getcount: { - type: [Boolean, String], - default: false - }, - getone: { - type: [Boolean, String], - default: false - }, - gettree: { - type: [Boolean, String], - default: false - }, - manual: { - type: Boolean, - default: false - }, - value: { - type: [Array, String, Number], - default () { - return [] - } - }, - modelValue: { - type: [Array, String, Number], - default () { - return [] - } - }, - preload: { - type: Boolean, - default: false - }, - stepSearh: { - type: Boolean, - default: true - }, - selfField: { - type: String, - default: '' - }, - parentField: { - type: String, - default: '' - }, - multiple: { - type: Boolean, - default: false - }, - map: { - type: Object, - default() { - return { - text: "text", - value: "value" - } - } - } - }, - data() { - return { - loading: false, - errorMessage: '', - loadMore: { - contentdown: '', - contentrefresh: '', - contentnomore: '' - }, - dataList: [], - selected: [], - selectedIndex: 0, - page: { - current: this.pageCurrent, - size: this.pageSize, - count: 0 - } - } - }, - computed: { - isLocaldata() { - return !this.collection.length - }, - postField() { - let fields = [this.field]; - if (this.parentField) { - fields.push(`${this.parentField} as parent_value`); - } - return fields.join(','); - }, - dataValue() { - let isModelValue = Array.isArray(this.modelValue) ? (this.modelValue.length > 0) : (this.modelValue !== null || this.modelValue !== undefined) - return isModelValue ? this.modelValue : this.value - }, - hasValue() { - if (typeof this.dataValue === 'number') { - return true - } - return (this.dataValue != null) && (this.dataValue.length > 0) - } - }, - created() { - this.$watch(() => { - var al = []; - ['pageCurrent', - 'pageSize', - 'spaceInfo', - 'value', - 'modelValue', - 'localdata', - 'collection', - 'action', - 'field', - 'orderby', - 'where', - 'getont', - 'getcount', - 'gettree' - ].forEach(key => { - al.push(this[key]) - }); - return al - }, (newValue, oldValue) => { - let needReset = false - for (let i = 2; i < newValue.length; i++) { - if (newValue[i] != oldValue[i]) { - needReset = true - break - } - } - if (newValue[0] != oldValue[0]) { - this.page.current = this.pageCurrent - } - this.page.size = this.pageSize - - this.onPropsChange() - }) - this._treeData = [] - }, - methods: { - onPropsChange() { - this._treeData = [] - }, - getCommand(options = {}) { - /* eslint-disable no-undef */ - let db = uniCloud.database(this.spaceInfo) - - const action = options.action || this.action - if (action) { - db = db.action(action) - } - - const collection = options.collection || this.collection - db = db.collection(collection) - - const where = options.where || this.where - if (!(!where || !Object.keys(where).length)) { - db = db.where(where) - } - - const field = options.field || this.field - if (field) { - db = db.field(field) - } - - const orderby = options.orderby || this.orderby - if (orderby) { - db = db.orderBy(orderby) - } - - const current = options.pageCurrent !== undefined ? options.pageCurrent : this.page.current - const size = options.pageSize !== undefined ? options.pageSize : this.page.size - const getCount = options.getcount !== undefined ? options.getcount : this.getcount - const getTree = options.gettree !== undefined ? options.gettree : this.gettree - - const getOptions = { - getCount, - getTree - } - if (options.getTreePath) { - getOptions.getTreePath = options.getTreePath - } - - db = db.skip(size * (current - 1)).limit(size).get(getOptions) - - return db - }, - getNodeData(callback) { - if (this.loading) { - return - } - this.loading = true - this.getCommand({ - field: this.postField, - where: this._pathWhere() - }).then((res) => { - this.loading = false - this.selected = res.result.data - callback && callback() - }).catch((err) => { - this.loading = false - this.errorMessage = err - }) - }, - getTreePath(callback) { - if (this.loading) { - return - } - this.loading = true - - this.getCommand({ - field: this.postField, - getTreePath: { - startWith: `${this.selfField}=='${this.dataValue}'` - } - }).then((res) => { - this.loading = false - let treePath = [] - this._extractTreePath(res.result.data, treePath) - this.selected = treePath - callback && callback() - }).catch((err) => { - this.loading = false - this.errorMessage = err - }) - }, - loadData() { - if (this.isLocaldata) { - this._processLocalData() - return - } - - if (this.dataValue != null) { - this._loadNodeData((data) => { - this._treeData = data - this._updateBindData() - this._updateSelected() - }) - return - } - - if (this.stepSearh) { - this._loadNodeData((data) => { - this._treeData = data - this._updateBindData() - }) - } else { - this._loadAllData((data) => { - this._treeData = [] - this._extractTree(data, this._treeData, null) - this._updateBindData() - }) - } - }, - _loadAllData(callback) { - if (this.loading) { - return - } - this.loading = true - - this.getCommand({ - field: this.postField, - gettree: true, - startwith: `${this.selfField}=='${this.dataValue}'` - }).then((res) => { - this.loading = false - callback(res.result.data) - this.onDataChange() - }).catch((err) => { - this.loading = false - this.errorMessage = err - }) - }, - _loadNodeData(callback, pw) { - if (this.loading) { - return - } - this.loading = true - - this.getCommand({ - field: this.postField, - where: pw || this._postWhere(), - pageSize: 500 - }).then((res) => { - this.loading = false - callback(res.result.data) - this.onDataChange() - }).catch((err) => { - this.loading = false - this.errorMessage = err - }) - }, - _pathWhere() { - let result = [] - let where_field = this._getParentNameByField(); - if (where_field) { - result.push(`${where_field} == '${this.dataValue}'`) - } - - if (this.where) { - return `(${this.where}) && (${result.join(' || ')})` - } - - return result.join(' || ') - }, - _postWhere() { - let result = [] - let selected = this.selected - let parentField = this.parentField - if (parentField) { - result.push(`${parentField} == null || ${parentField} == ""`) - } - if (selected.length) { - for (var i = 0; i < selected.length - 1; i++) { - result.push(`${parentField} == '${selected[i].value}'`) - } - } - - let where = [] - if (this.where) { - where.push(`(${this.where})`) - } - if (result.length) { - where.push(`(${result.join(' || ')})`) - } - - return where.join(' && ') - }, - _nodeWhere() { - let result = [] - let selected = this.selected - if (selected.length) { - result.push(`${this.parentField} == '${selected[selected.length - 1].value}'`) - } - - if (this.where) { - return `(${this.where}) && (${result.join(' || ')})` - } - - return result.join(' || ') - }, - _getParentNameByField() { - const fields = this.field.split(','); - let where_field = null; - for (let i = 0; i < fields.length; i++) { - const items = fields[i].split('as'); - if (items.length < 2) { - continue; - } - if (items[1].trim() === 'value') { - where_field = items[0].trim(); - break; - } - } - return where_field - }, - _isTreeView() { - return (this.parentField && this.selfField) - }, - _updateSelected() { - var dl = this.dataList - var sl = this.selected - let textField = this.map.text - let valueField = this.map.value - for (var i = 0; i < sl.length; i++) { - var value = sl[i].value - var dl2 = dl[i] - for (var j = 0; j < dl2.length; j++) { - var item2 = dl2[j] - if (item2[valueField] === value) { - sl[i].text = item2[textField] - break - } - } - } - }, - _updateBindData(node) { - const { - dataList, - hasNodes - } = this._filterData(this._treeData, this.selected) - - let isleaf = this._stepSearh === false && !hasNodes - - if (node) { - node.isleaf = isleaf - } - - this.dataList = dataList - this.selectedIndex = dataList.length - 1 - - if (!isleaf && this.selected.length < dataList.length) { - this.selected.push({ - value: null, - text: "请选择" - }) - } - - return { - isleaf, - hasNodes - } - }, - _filterData(data, paths) { - let dataList = [] - let hasNodes = true - - dataList.push(data.filter((item) => { - return (item.parent_value === null || item.parent_value === undefined || item.parent_value === '') - })) - for (let i = 0; i < paths.length; i++) { - var value = paths[i].value - var nodes = data.filter((item) => { - return item.parent_value === value - }) - - if (nodes.length) { - dataList.push(nodes) - } else { - hasNodes = false - } - } - - return { - dataList, - hasNodes - } - }, - _extractTree(nodes, result, parent_value) { - let list = result || [] - let valueField = this.map.value - for (let i = 0; i < nodes.length; i++) { - let node = nodes[i] - - let child = {} - for (let key in node) { - if (key !== 'children') { - child[key] = node[key] - } - } - if (parent_value !== null && parent_value !== undefined && parent_value !== '') { - child.parent_value = parent_value - } - result.push(child) - - let children = node.children - if (children) { - this._extractTree(children, result, node[valueField]) - } - } - }, - _extractTreePath(nodes, result) { - let list = result || [] - for (let i = 0; i < nodes.length; i++) { - let node = nodes[i] - - let child = {} - for (let key in node) { - if (key !== 'children') { - child[key] = node[key] - } - } - result.push(child) - - let children = node.children - if (children) { - this._extractTreePath(children, result) - } - } - }, - _findNodePath(key, nodes, path = []) { - let textField = this.map.text - let valueField = this.map.value - for (let i = 0; i < nodes.length; i++) { - let node = nodes[i] - let children = node.children - let text = node[textField] - let value = node[valueField] - - path.push({ - value, - text - }) - - if (value === key) { - return path - } - - if (children) { - const p = this._findNodePath(key, children, path) - if (p.length) { - return p - } - } - - path.pop() - } - return [] - }, - _processLocalData() { - this._treeData = [] - this._extractTree(this.localdata, this._treeData) - - var inputValue = this.dataValue - if (inputValue === undefined) { - return - } - - if (Array.isArray(inputValue)) { - inputValue = inputValue[inputValue.length - 1] - if (typeof inputValue === 'object' && inputValue[this.map.value]) { - inputValue = inputValue[this.map.value] - } - } - - this.selected = this._findNodePath(inputValue, this.localdata) - } - } -} +export default { + props: { + localdata: { + type: [Array, Object], + default () { + return [] + } + }, + spaceInfo: { + type: Object, + default () { + return {} + } + }, + collection: { + type: String, + default: '' + }, + action: { + type: String, + default: '' + }, + field: { + type: String, + default: '' + }, + orderby: { + type: String, + default: '' + }, + where: { + type: [String, Object], + default: '' + }, + pageData: { + type: String, + default: 'add' + }, + pageCurrent: { + type: Number, + default: 1 + }, + pageSize: { + type: Number, + default: 20 + }, + getcount: { + type: [Boolean, String], + default: false + }, + getone: { + type: [Boolean, String], + default: false + }, + gettree: { + type: [Boolean, String], + default: false + }, + manual: { + type: Boolean, + default: false + }, + value: { + type: [Array, String, Number], + default () { + return [] + } + }, + modelValue: { + type: [Array, String, Number], + default () { + return [] + } + }, + preload: { + type: Boolean, + default: false + }, + stepSearh: { + type: Boolean, + default: true + }, + selfField: { + type: String, + default: '' + }, + parentField: { + type: String, + default: '' + }, + multiple: { + type: Boolean, + default: false + }, + map: { + type: Object, + default() { + return { + text: "text", + value: "value" + } + } + } + }, + data() { + return { + loading: false, + errorMessage: '', + loadMore: { + contentdown: '', + contentrefresh: '', + contentnomore: '' + }, + dataList: [], + selected: [], + selectedIndex: 0, + page: { + current: this.pageCurrent, + size: this.pageSize, + count: 0 + } + } + }, + computed: { + isLocaldata() { + return !this.collection.length + }, + postField() { + let fields = [this.field]; + if (this.parentField) { + fields.push(`${this.parentField} as parent_value`); + } + return fields.join(','); + }, + dataValue() { + let isModelValue = Array.isArray(this.modelValue) ? (this.modelValue.length > 0) : (this.modelValue !== null || this.modelValue !== undefined) + return isModelValue ? this.modelValue : this.value + }, + hasValue() { + if (typeof this.dataValue === 'number') { + return true + } + return (this.dataValue != null) && (this.dataValue.length > 0) + } + }, + created() { + this.$watch(() => { + var al = []; + ['pageCurrent', + 'pageSize', + 'spaceInfo', + 'value', + 'modelValue', + 'localdata', + 'collection', + 'action', + 'field', + 'orderby', + 'where', + 'getont', + 'getcount', + 'gettree' + ].forEach(key => { + al.push(this[key]) + }); + return al + }, (newValue, oldValue) => { + let needReset = false + for (let i = 2; i < newValue.length; i++) { + if (newValue[i] != oldValue[i]) { + needReset = true + break + } + } + if (newValue[0] != oldValue[0]) { + this.page.current = this.pageCurrent + } + this.page.size = this.pageSize + + this.onPropsChange() + }) + this._treeData = [] + }, + methods: { + onPropsChange() { + this._treeData = [] + }, + getCommand(options = {}) { + /* eslint-disable no-undef */ + let db = uniCloud.database(this.spaceInfo) + + const action = options.action || this.action + if (action) { + db = db.action(action) + } + + const collection = options.collection || this.collection + db = db.collection(collection) + + const where = options.where || this.where + if (!(!where || !Object.keys(where).length)) { + db = db.where(where) + } + + const field = options.field || this.field + if (field) { + db = db.field(field) + } + + const orderby = options.orderby || this.orderby + if (orderby) { + db = db.orderBy(orderby) + } + + const current = options.pageCurrent !== undefined ? options.pageCurrent : this.page.current + const size = options.pageSize !== undefined ? options.pageSize : this.page.size + const getCount = options.getcount !== undefined ? options.getcount : this.getcount + const getTree = options.gettree !== undefined ? options.gettree : this.gettree + + const getOptions = { + getCount, + getTree + } + if (options.getTreePath) { + getOptions.getTreePath = options.getTreePath + } + + db = db.skip(size * (current - 1)).limit(size).get(getOptions) + + return db + }, + getNodeData(callback) { + if (this.loading) { + return + } + this.loading = true + this.getCommand({ + field: this.postField, + where: this._pathWhere() + }).then((res) => { + this.loading = false + this.selected = res.result.data + callback && callback() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + getTreePath(callback) { + if (this.loading) { + return + } + this.loading = true + + this.getCommand({ + field: this.postField, + getTreePath: { + startWith: `${this.selfField}=='${this.dataValue}'` + } + }).then((res) => { + this.loading = false + let treePath = [] + this._extractTreePath(res.result.data, treePath) + this.selected = treePath + callback && callback() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + loadData() { + if (this.isLocaldata) { + this._processLocalData() + return + } + + if (this.dataValue != null) { + this._loadNodeData((data) => { + this._treeData = data + this._updateBindData() + this._updateSelected() + }) + return + } + + if (this.stepSearh) { + this._loadNodeData((data) => { + this._treeData = data + this._updateBindData() + }) + } else { + this._loadAllData((data) => { + this._treeData = [] + this._extractTree(data, this._treeData, null) + this._updateBindData() + }) + } + }, + _loadAllData(callback) { + if (this.loading) { + return + } + this.loading = true + + this.getCommand({ + field: this.postField, + gettree: true, + startwith: `${this.selfField}=='${this.dataValue}'` + }).then((res) => { + this.loading = false + callback(res.result.data) + this.onDataChange() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + _loadNodeData(callback, pw) { + if (this.loading) { + return + } + this.loading = true + + this.getCommand({ + field: this.postField, + where: pw || this._postWhere(), + pageSize: 500 + }).then((res) => { + this.loading = false + callback(res.result.data) + this.onDataChange() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + _pathWhere() { + let result = [] + let where_field = this._getParentNameByField(); + if (where_field) { + result.push(`${where_field} == '${this.dataValue}'`) + } + + if (this.where) { + return `(${this.where}) && (${result.join(' || ')})` + } + + return result.join(' || ') + }, + _postWhere() { + let result = [] + let selected = this.selected + let parentField = this.parentField + if (parentField) { + result.push(`${parentField} == null || ${parentField} == ""`) + } + if (selected.length) { + for (var i = 0; i < selected.length - 1; i++) { + result.push(`${parentField} == '${selected[i].value}'`) + } + } + + let where = [] + if (this.where) { + where.push(`(${this.where})`) + } + if (result.length) { + where.push(`(${result.join(' || ')})`) + } + + return where.join(' && ') + }, + _nodeWhere() { + let result = [] + let selected = this.selected + if (selected.length) { + result.push(`${this.parentField} == '${selected[selected.length - 1].value}'`) + } + + if (this.where) { + return `(${this.where}) && (${result.join(' || ')})` + } + + return result.join(' || ') + }, + _getParentNameByField() { + const fields = this.field.split(','); + let where_field = null; + for (let i = 0; i < fields.length; i++) { + const items = fields[i].split('as'); + if (items.length < 2) { + continue; + } + if (items[1].trim() === 'value') { + where_field = items[0].trim(); + break; + } + } + return where_field + }, + _isTreeView() { + return (this.parentField && this.selfField) + }, + _updateSelected() { + var dl = this.dataList + var sl = this.selected + let textField = this.map.text + let valueField = this.map.value + for (var i = 0; i < sl.length; i++) { + var value = sl[i].value + var dl2 = dl[i] + for (var j = 0; j < dl2.length; j++) { + var item2 = dl2[j] + if (item2[valueField] === value) { + sl[i].text = item2[textField] + break + } + } + } + }, + _updateBindData(node) { + const { + dataList, + hasNodes + } = this._filterData(this._treeData, this.selected) + + let isleaf = this._stepSearh === false && !hasNodes + + if (node) { + node.isleaf = isleaf + } + + this.dataList = dataList + this.selectedIndex = dataList.length - 1 + + if (!isleaf && this.selected.length < dataList.length) { + this.selected.push({ + value: null, + text: "请选择" + }) + } + + return { + isleaf, + hasNodes + } + }, + _filterData(data, paths) { + let dataList = [] + let hasNodes = true + + dataList.push(data.filter((item) => { + return (item.parent_value === null || item.parent_value === undefined || item.parent_value === '') + })) + for (let i = 0; i < paths.length; i++) { + var value = paths[i].value + var nodes = data.filter((item) => { + return item.parent_value === value + }) + + if (nodes.length) { + dataList.push(nodes) + } else { + hasNodes = false + } + } + + return { + dataList, + hasNodes + } + }, + _extractTree(nodes, result, parent_value) { + let list = result || [] + let valueField = this.map.value + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i] + + let child = {} + for (let key in node) { + if (key !== 'children') { + child[key] = node[key] + } + } + if (parent_value !== null && parent_value !== undefined && parent_value !== '') { + child.parent_value = parent_value + } + result.push(child) + + let children = node.children + if (children) { + this._extractTree(children, result, node[valueField]) + } + } + }, + _extractTreePath(nodes, result) { + let list = result || [] + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i] + + let child = {} + for (let key in node) { + if (key !== 'children') { + child[key] = node[key] + } + } + result.push(child) + + let children = node.children + if (children) { + this._extractTreePath(children, result) + } + } + }, + _findNodePath(key, nodes, path = []) { + let textField = this.map.text + let valueField = this.map.value + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i] + let children = node.children + let text = node[textField] + let value = node[valueField] + + path.push({ + value, + text + }) + + if (value === key) { + return path + } + + if (children) { + const p = this._findNodePath(key, children, path) + if (p.length) { + return p + } + } + + path.pop() + } + return [] + }, + _processLocalData() { + this._treeData = [] + this._extractTree(this.localdata, this._treeData) + + var inputValue = this.dataValue + if (inputValue === undefined) { + return + } + + if (Array.isArray(inputValue)) { + inputValue = inputValue[inputValue.length - 1] + if (typeof inputValue === 'object' && inputValue[this.map.value]) { + inputValue = inputValue[this.map.value] + } + } + + this.selected = this._findNodePath(inputValue, this.localdata) + } + } +} diff --git a/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue b/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue index 44b72ca..e6c187a 100644 --- a/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue +++ b/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue @@ -5,16 +5,16 @@ -