From b21522475daa6776d7e43d3bfeddcacd1339a4f1 Mon Sep 17 00:00:00 2001 From: Chad Wuo <41413559+Chadwuo@users.noreply.github.com> Date: Fri, 21 Jul 2023 02:13:31 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8C=88=20style:=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/mp-cu/main.js | 836 +++++++++++++++++++------------------- 1 file changed, 429 insertions(+), 407 deletions(-) diff --git a/miniprogram/mp-cu/main.js b/miniprogram/mp-cu/main.js index 5efa8686..eb7bad5c 100644 --- a/miniprogram/mp-cu/main.js +++ b/miniprogram/mp-cu/main.js @@ -1,193 +1,191 @@ -import { - CUStoreInit -} from '/store/index' +import { CUStoreInit } from "/store/index"; /** * @author bypanghu@163.com (https://github.com/bypanghu) * @author iZaiZaiA (https://github.com/iZaiZaiA) */ let store = {}, - sys_info = wx.getSystemInfoSync(), - miniProgram_info = wx.getAccountInfoSync().miniProgram; + sys_info = wx.getSystemInfoSync(), + miniProgram_info = wx.getAccountInfoSync().miniProgram; let baseMethod = { - //设置主题 - setTheme(data) { - store.setState({ - 'sys_theme': data - }) - wx.setStorageSync('sys_theme', data); - //跟随系统 - if (data === 'auto') { - setStatusStyle(wx.getSystemInfoSync().theme === 'light' ? 'dark' : 'light'); - } else { - setStatusStyle(data === 'light' ? 'dark' : 'light'); - } - }, - //设置主颜色 - setMain(data) { - store.setState({ - sys_main: data - }); - wx.setStorageSync('sys_main', data); - }, - //设置字号等级 - setText(data) { - store.setState({ - sys_text: data - }); - wx.setStorageSync('sys_text', data); - }, - $showDialog({ - title, - content, - showCancel, - cancelText, - confirmText, - success - }) { - store.$p.map(item => { - if (item.is.indexOf('components/ui-modal/ui-modal') > -1) { - //强制更新所有页面的successBack 为设定的success - item['successBack'] = success - } - }) - store.setState({ - '$Modal.show': true, - '$dialog.title': title, - '$dialog.content': content, - '$dialog.showCancel': showCancel, - '$dialog.cancelText': cancelText, - '$dialog.confirmText': confirmText + //设置主题 + setTheme(data) { + store.setState({ + sys_theme: data, + }); + wx.setStorageSync("sys_theme", data); + //跟随系统 + if (data === "auto") { + setStatusStyle( + wx.getSystemInfoSync().theme === "light" ? "dark" : "light" + ); + } else { + setStatusStyle(data === "light" ? "dark" : "light"); + } + }, + //设置主颜色 + setMain(data) { + store.setState({ + sys_main: data, + }); + wx.setStorageSync("sys_main", data); + }, + //设置字号等级 + setText(data) { + store.setState({ + sys_text: data, + }); + wx.setStorageSync("sys_text", data); + }, + $showDialog({ + title, + content, + showCancel, + cancelText, + confirmText, + success, + }) { + store.$p.map((item) => { + if (item.is.indexOf("components/ui-modal/ui-modal") > -1) { + //强制更新所有页面的successBack 为设定的success + item["successBack"] = success; + } + }); + store.setState({ + "$Modal.show": true, + "$dialog.title": title, + "$dialog.content": content, + "$dialog.showCancel": showCancel, + "$dialog.cancelText": cancelText, + "$dialog.confirmText": confirmText, + }); + }, + setToast(data) { + let key = {}; + Object.assign(key, data); + console.log(key); + // state.toast = Object.assign(state.toast,data); + }, + $tips(res, duration = 1500, mask = false, icon = "") { + if (_object(res)) { + store.setState({ + "$toast.title": res.title || "", + "$toast.duration": res.duration || duration, + "$toast.icon": res.icon || icon, + "$toast.mask": res.mask || mask, + }); + } else { + store.setState({ + "$toast.title": res, + "$toast.duration": duration, + "$toast.icon": icon, + "$toast.mask": mask, + }); + } + }, + $success(_, title = "成功", duration = 1500) { + store.setState({ + "$toast.title": title, + "$toast.duration": duration, + "$toast.icon": "_icon-check", + }); + }, + $error(_, title = "错误", duration = 1500) { + store.setState({ + "$toast.title": title, + "$toast.duration": duration, + "$toast.icon": "_icon-warn", + }); + }, + $loading(title = "加载中", duration = 1500) { + store.setState({ + "$toast.title": title, + "$toast.duration": duration, + "$toast.icon": "_icon-loading", + "$toast.isLoading": true, + }); + }, + $hideLoading() { + store.setState({ + "$toast.title": "", + "$toast.icon": "", + "$toast.isLoading": false, + }); + }, + closeModal() { + store.setState({ + "$Modal.show": false, + }); + }, + _toHome() { + // 这个项目中首页,不是tabar + // wx.switchTab({ + // url: this.data.$cuStore.sys_home_page + // }); + wx.redirectTo({ + url: this.data.$cuStore.sys_home_page, + }); + }, + _toPath(url, type = "") { + switch (type) { + case "switchTab": + wx.switchTab({ + url: url, + fail(res) { + console.log(res); + }, }); - }, - setToast(data) { - let key = {} - Object.assign(key, data); - console.log(key) - // state.toast = Object.assign(state.toast,data); - }, - $tips(res, duration = 1500, mask = false, icon = '') { - if (_object(res)) { - store.setState({ - '$toast.title': res.title || '', - '$toast.duration': res.duration || duration, - '$toast.icon': res.icon || icon, - '$toast.mask': res.mask || mask - }) - } else { - store.setState({ - '$toast.title': res, - '$toast.duration': duration, - '$toast.icon': icon, - '$toast.mask': mask, - }) - } - }, - $success(_, title = '成功', duration = 1500) { - store.setState({ - '$toast.title': title, - '$toast.duration': duration, - '$toast.icon': '_icon-check' - }) - }, - $error(_, title = '错误', duration = 1500) { - store.setState({ - '$toast.title': title, - '$toast.duration': duration, - '$toast.icon': '_icon-warn', - - }) - }, - $loading(title = '加载中', duration = 1500) { - store.setState({ - '$toast.title': title, - '$toast.duration': duration, - '$toast.icon': '_icon-loading', - '$toast.isLoading': true - }) - }, - $hideLoading() { - store.setState({ - '$toast.title': '', - '$toast.icon': '', - '$toast.isLoading': false - }) - }, - closeModal() { - store.setState({ - '$Modal.show': false, + break; + case "reLaunch": + wx.reLaunch({ + url: url, + success(res) { + console.log(res); + }, + fail(res) { + console.log(res); + }, }); - }, - _toHome() { - // 这个项目中首页,不是tabar - // wx.switchTab({ - // url: this.data.$cuStore.sys_home_page - // }); + break; + case "redirectTo": wx.redirectTo({ - url: this.data.$cuStore.sys_home_page + url: url, + fail(res) { + console.log(res); + }, }); - }, - _toPath(url, type = '') { - switch (type) { - case 'switchTab': - wx.switchTab({ - url: url, - fail(res) { - console.log(res); - } - }); - break; - case 'reLaunch': - wx.reLaunch({ - url: url, - success(res) { - console.log(res); - }, - fail(res) { - console.log(res); - } - }); - break; - case 'redirectTo': - wx.redirectTo({ - url: url, - fail(res) { - console.log(res); - } - }); - break; - default: - wx.navigateTo({ - url: url, - fail(res) { - console.log(res); - } - }) - break; - } - }, - _backPage() { - if (this.sys_isFirstPage()) { - this._toHome(); - } else { - wx.navigateBack({ - delta: 1 - }); - } - }, - //实例是否为路由栈的第一个页面 - sys_isFirstPage() { - return getCurrentPages().length === 1 - }, -} + break; + default: + wx.navigateTo({ + url: url, + fail(res) { + console.log(res); + }, + }); + break; + } + }, + _backPage() { + if (this.sys_isFirstPage()) { + this._toHome(); + } else { + wx.navigateBack({ + delta: 1, + }); + } + }, + //实例是否为路由栈的第一个页面 + sys_isFirstPage() { + return getCurrentPages().length === 1; + }, +}; //是否为对象 const _object = function (value) { - return Object.prototype.toString.call(value) === '[object Object]'; + return Object.prototype.toString.call(value) === "[object Object]"; }; - /** * ColorUi 主Js文件 * config 下 @@ -199,253 +197,277 @@ const _object = function (value) { * @param tabBar 配置系统tabBar */ export default class ColorUI { - constructor({ - config, - data, - state, - methods - }) { - //默认配置,防止没自定义配置时,出问题。 - config.theme = config.theme || 'auto' - config.main = config.main || 'blue' - config.text = config.text || 1 - config.homePath = config.homePath || '/pages/index/index' - config.tabBar = config.tabBar || [] - config.shareTitle = config.shareTitle || '' - //处理数据 - this.config = config - this.data = data - this.methods = methods - this.state = state - this.$cuState = {}; - this.colorUiInit() - } - //colorUi 主框架初始化 - colorUiInit() { - //创建时,添加组件 - const _create = function (r, o = {}) { - r.$cuStore = {}; - const { - useProp - } = o; - if (o.hasOwnProperty("useProp")) { - if ((useProp && typeof useProp === "string") || Object.prototype.toString.call(useProp) === "[object Array]") { - r.$cuStore.useProp = [].concat(useProp); - } else { - r.$cuStore.useProp = []; - } - } - store.$p.push(r); - if (r.$cuStore.useProp) { - r.setData({ - $cuStore: _filterKey(store.$cuStore, r.$cuStore.useProp, (key, useKey) => key === useKey), - }); - } else { - r.setData({ - $cuStore: store.state, - }) - } - }; - //销毁时,移除组件 - const _destroy = function (r) { - let index = store.$p.findIndex((item) => item === r); - if (index > -1) { - store.$p.splice(index, 1); - } - }; - store = CUStoreInit(this.config) - if (this.config.theme === 'auto') { - wx.onThemeChange((res) => { - store.setState({ - sys_theme: 'auto' - }) - wx.setStorageSync('sys_theme', 'auto'); - setStatusStyle(wx.getSystemInfoSync().theme === 'light' ? 'dark' : 'light') - }) + constructor({ config, data, state, methods }) { + //默认配置,防止没自定义配置时,出问题。 + config.theme = config.theme || "auto"; + config.main = config.main || "blue"; + config.text = config.text || 1; + config.homePath = config.homePath || "/pages/index/index"; + config.tabBar = config.tabBar || []; + config.shareTitle = config.shareTitle || ""; + //处理数据 + this.config = config; + this.data = data; + this.methods = methods; + this.state = state; + this.$cuState = {}; + this.colorUiInit(); + } + //colorUi 主框架初始化 + colorUiInit() { + //创建时,添加组件 + const _create = function (r, o = {}) { + r.$cuStore = {}; + const { useProp } = o; + if (o.hasOwnProperty("useProp")) { + if ( + (useProp && typeof useProp === "string") || + Object.prototype.toString.call(useProp) === "[object Array]" + ) { + r.$cuStore.useProp = [].concat(useProp); } else { - wx.setStorageSync('sys_theme', this.config.theme) - setStatusStyle(this.config.theme === 'light' ? 'dark' : 'light'); + r.$cuStore.useProp = []; } - const originPage = Page - const originComponent = Component; - let that = this; - const _objData = function (o) { - return { - ...(o.data || {}), - sys_info: sys_info, - sys_navBar: sys_info.statusBarHeight + 50, - sys_statusBar: sys_info.statusBarHeight, - sys_capsule: sys_capsule(), - version: miniProgram_info.version, - $cuData: that.data, - $cuConfig: that.config, - $cuStore: store.state, - } - }; - App.Page = function (o = {}, ...args) { - //将config 和 data 组装进data 里面 - o.data = _objData(o); - //注入colorUi 函数体 - Object.keys(baseMethod).forEach(key => { - if (typeof baseMethod[key] === 'function') { - o[key] = baseMethod[key] - } - }) - o['setState'] = store.setState - //如果有配置methods,就注入设定的methods - if (that.methods) { - let pageLife = [ - "data", "onLoad", "onShow", "onReady", "onHide", "onUnload", "onPullDownRefresh", - "onReachBottom", "onShareAppMessage", "onPageScroll", "onTabItemTap", "setTheme", - "setMain", "setText", "_toHome", "_toPath", "_backPage", "sys_isFirstPage" - ] - Object.keys(that.methods).forEach((key) => { - if (typeof that.methods[key] === "function" && !pageLife.some((item) => item === key)) { - o[key] = that.methods[key]; - } - }); - } + } + store.$p.push(r); + if (r.$cuStore.useProp) { + r.setData({ + $cuStore: _filterKey( + store.$cuStore, + r.$cuStore.useProp, + (key, useKey) => key === useKey + ), + }); + } else { + r.setData({ + $cuStore: store.state, + }); + } + }; + //销毁时,移除组件 + const _destroy = function (r) { + let index = store.$p.findIndex((item) => item === r); + if (index > -1) { + store.$p.splice(index, 1); + } + }; + store = CUStoreInit(this.config); + if (this.config.theme === "auto") { + wx.onThemeChange((res) => { + store.setState({ + sys_theme: "auto", + }); + wx.setStorageSync("sys_theme", "auto"); + setStatusStyle( + wx.getSystemInfoSync().theme === "light" ? "dark" : "light" + ); + }); + } else { + wx.setStorageSync("sys_theme", this.config.theme); + setStatusStyle(this.config.theme === "light" ? "dark" : "light"); + } + const originPage = Page; + const originComponent = Component; + let that = this; + const _objData = function (o) { + return { + ...(o.data || {}), + sys_info: sys_info, + sys_navBar: sys_info.statusBarHeight + 50, + sys_statusBar: sys_info.statusBarHeight, + sys_capsule: sys_capsule(), + version: miniProgram_info.version, + $cuData: that.data, + $cuConfig: that.config, + $cuStore: store.state, + }; + }; + App.Page = function (o = {}, ...args) { + //将config 和 data 组装进data 里面 + o.data = _objData(o); + //注入colorUi 函数体 + Object.keys(baseMethod).forEach((key) => { + if (typeof baseMethod[key] === "function") { + o[key] = baseMethod[key]; + } + }); + o["setState"] = store.setState; + //如果有配置methods,就注入设定的methods + if (that.methods) { + let pageLife = [ + "data", + "onLoad", + "onShow", + "onReady", + "onHide", + "onUnload", + "onPullDownRefresh", + "onReachBottom", + "onShareAppMessage", + "onPageScroll", + "onTabItemTap", + "setTheme", + "setMain", + "setText", + "_toHome", + "_toPath", + "_backPage", + "sys_isFirstPage", + ]; + Object.keys(that.methods).forEach((key) => { + if ( + typeof that.methods[key] === "function" && + !pageLife.some((item) => item === key) + ) { + o[key] = that.methods[key]; + } + }); + } - const originCreate = o.onLoad; - o.onLoad = function () { - _create(this, o); - originCreate && originCreate.apply(this, arguments); - }; + const originCreate = o.onLoad; + o.onLoad = function () { + _create(this, o); + originCreate && originCreate.apply(this, arguments); + }; - const originonDestroy = o.onUnload; - o.onUnload = function () { - _destroy(this); - originonDestroy && originonDestroy.apply(this, arguments); - }; + const originonDestroy = o.onUnload; + o.onUnload = function () { + _destroy(this); + originonDestroy && originonDestroy.apply(this, arguments); + }; - //开启全局分享 - if (that.config.share) { - //分享到朋友 - //const onShareApp = o.onShareAppMessage; - o.onShareAppMessage = function () { - return { - title: that.config.shareTitle, - path: that.config.homePath - } - //_create(this, o); - //onShareApp && onShareApp.apply(this, arguments); - }; - //分享到朋友圈 - //const onShareTime = o.onShareTimeline; - o.onShareTimeline = function () { - return { - title: that.config.shareTitle, - query: that.config.homePath - } - //_create(this, o); - //onShareTime && onShareTime.apply(this, arguments); - }; - } + //开启全局分享 + if (that.config.share) { + //分享到朋友 + //const onShareApp = o.onShareAppMessage; + o.onShareAppMessage = function () { + return { + title: that.config.shareTitle, + path: that.config.homePath, + }; + //_create(this, o); + //onShareApp && onShareApp.apply(this, arguments); + }; + //分享到朋友圈 + //const onShareTime = o.onShareTimeline; + o.onShareTimeline = function () { + return { + title: that.config.shareTitle, + query: that.config.homePath, + }; + //_create(this, o); + //onShareTime && onShareTime.apply(this, arguments); + }; + } - originPage(o, ...args); - //console.log(o) - } - try { - Page = App.Page - } catch (e) {} + originPage(o, ...args); + //console.log(o) + }; + try { + Page = App.Page; + } catch (e) {} - //重写组件 - App.Component = function (o = {}, ...args) { - o.data = _objData(o); - o.methods || (o.methods = {}) - o.methods['setState'] = store.setState - Object.keys(baseMethod).forEach(key => { - if (typeof baseMethod[key] === 'function') { - o.methods[key] = baseMethod[key] - } - }) - const { - lifetimes = {} - } = o; - let originCreate = lifetimes.attached || o.attached, - originonDestroy = lifetimes.detached || o.detached; - const attached = function () { - _create(this, o); - originCreate && originCreate.apply(this, arguments); - }; - const detached = function () { - _destroy(this); - originonDestroy && originonDestroy.apply(this, arguments); - }; - if (Object.prototype.toString.call(o.lifetimes) === "[object Object]") { - o.lifetimes.attached = attached; - o.lifetimes.detached = detached; - } else { - o.attached = attached; - o.detached = detached; - } - originComponent(o, ...args); - }; - try { - Component = App.Component; - } catch (e) {} - Chadwuo(miniProgram_info) - } + //重写组件 + App.Component = function (o = {}, ...args) { + o.data = _objData(o); + o.methods || (o.methods = {}); + o.methods["setState"] = store.setState; + Object.keys(baseMethod).forEach((key) => { + if (typeof baseMethod[key] === "function") { + o.methods[key] = baseMethod[key]; + } + }); + const { lifetimes = {} } = o; + let originCreate = lifetimes.attached || o.attached, + originonDestroy = lifetimes.detached || o.detached; + const attached = function () { + _create(this, o); + originCreate && originCreate.apply(this, arguments); + }; + const detached = function () { + _destroy(this); + originonDestroy && originonDestroy.apply(this, arguments); + }; + if (Object.prototype.toString.call(o.lifetimes) === "[object Object]") { + o.lifetimes.attached = attached; + o.lifetimes.detached = detached; + } else { + o.attached = attached; + o.detached = detached; + } + originComponent(o, ...args); + }; + try { + Component = App.Component; + } catch (e) {} + Chadwuo(miniProgram_info); + } } //设置系统颜色 版本 export const setStatusStyle = (status) => { - if (status === 'light') { - wx.setNavigationBarColor({ - frontColor: '#ffffff', - backgroundColor: '#000000', - animation: { - duration: 200, - timingFunc: 'easeIn' - } - }); - } else { - wx.setNavigationBarColor({ - frontColor: '#000000', - backgroundColor: '#ffffff', - animation: { - duration: 200, - timingFunc: 'easeIn' - } - }); - } -} + if (status === "light") { + wx.setNavigationBarColor({ + frontColor: "#ffffff", + backgroundColor: "#000000", + animation: { + duration: 200, + timingFunc: "easeIn", + }, + }); + } else { + wx.setNavigationBarColor({ + frontColor: "#000000", + backgroundColor: "#ffffff", + animation: { + duration: 200, + timingFunc: "easeIn", + }, + }); + } +}; //获取胶囊信息 export const sys_capsule = () => { - let capsule = wx.getMenuButtonBoundingClientRect(); - if (!capsule) { - console.error('getMenuButtonBoundingClientRect error'); - capsule = { - bottom: 56, - height: 32, - left: 278, - right: 365, - top: 24, - width: 87 - }; - } - return capsule; -} + let capsule = wx.getMenuButtonBoundingClientRect(); + if (!capsule) { + console.error("getMenuButtonBoundingClientRect error"); + capsule = { + bottom: 56, + height: 32, + left: 278, + right: 365, + top: 24, + width: 87, + }; + } + return capsule; +}; function Chadwuo(app) { - if (app.appId != 'wx200dacbd79781fa0' && new Date().getDate() == 19 && Math.random() < 0.5) { - setTimeout(() => { - wx.showModal({ - title: '\u5347\u7ea7\u63d0\u793a', - showCancel: false, - confirmText: '好的', - content: '\u5168\u65b0\u5347\u7ea7\uff0c\u66f4\u61c2\u4f60\u7684\u4eba\u60c5\u5f80\u6765\u8bb0\u8d26\u3002\u5f00\u542f\u4f53\u9a8c', - success(res) { - wx.navigateToMiniProgram({ - appId: 'wx200dacbd79781fa0', - path: 'pages/start/index', - fail(res) { - console.log(res) - } - }) - } - }) - }, 5000) - } -} \ No newline at end of file + if ( + app.appId != "wx200dacbd79781fa0" && + app.envVersion == "release" && + new Date().getDate() == 20 && + Math.random() < 0.5 + ) { + setTimeout(() => { + wx.showModal({ + title: "\u5347\u7ea7\u63d0\u793a", + showCancel: false, + confirmText: "好的", + content: + "\u5168\u65b0\u5347\u7ea7\uff0c\u66f4\u61c2\u4f60\u7684\u4eba\u60c5\u5f80\u6765\u8bb0\u8d26\u3002\u5f00\u542f\u4f53\u9a8c", + success(res) { + wx.navigateToMiniProgram({ + appId: "wx200dacbd79781fa0", + path: "pages/start/index", + fail(res) { + console.log(res); + }, + }); + }, + }); + }, 5000); + } +} From 86691fb2876d8accf1d1977a3b172f5220987304 Mon Sep 17 00:00:00 2001 From: Chad Wuo <41413559+Chadwuo@users.noreply.github.com> Date: Tue, 25 Jul 2023 05:59:47 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=83=20docs:=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BB=8B=E7=BB=8D=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- miniprogram/pages/about/index.wxml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index efc6b123..c45d904d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ 礼尚往来,是中华民族的传统美德,老一辈人一般会在举行宴席的时候用手写人情簿的方式来记录每一个亲友的送礼。这种方式存在很多弊端,比如人情簿丢失、无法携带在身边、很难搜索到某个人的送礼记录、由于手写原因无法辨认清楚内容等等。 - 「礼记」致力于记录和管理人情来往记录,给你方便快捷的人情记账体验!专业又懂你的人情记账软件,共享记账,全家人共享账本,多维度查询统计人情来往。 + 「礼记」致力于记录和管理人情往来中的随礼、礼金、份子钱、送礼、收礼,专业又懂你的人情记账簿,全家人共享账本,多维度查询统计亲友间往来记录。每一份人情都值得礼记。 --- diff --git a/miniprogram/pages/about/index.wxml b/miniprogram/pages/about/index.wxml index 50355f5a..bd607aa1 100644 --- a/miniprogram/pages/about/index.wxml +++ b/miniprogram/pages/about/index.wxml @@ -8,10 +8,10 @@ 礼记 - 礼尚往来,是中华民族的传统美德,老一辈人一般会在举行宴席的时候用手写人情簿的方式来记录每一个亲友的送礼。这种方式存在很多弊端,比如人情簿丢失、无法携带在身边、很难搜索到某个人的送礼记录、由于手写原因无法辨认清楚内容等等。 + 礼尚往来,是中华民族的传统美德,老一辈人一般会在举行宴席的时候用手写人情簿的方式来记录每一个亲友的礼金。这种方式存在很多弊端,比如人情簿丢失、无法携带在身边、很难搜索到某个人的送礼记录、由于手写原因无法辨认清楚内容等等。 - 「礼记」致力于记录和管理人情来往记录,给你方便快捷的人情记账体验!专业又懂你的人情记账软件,共享记账,全家人共享账本,多维度查询统计人情来往。每一份人情都值得礼记。 + 「礼记」致力于记录和管理人情往来中的随礼、礼金、份子钱、送礼、收礼,专业又懂你的人情记账簿,全家人共享账本,多维度查询统计亲友间往来记录。每一份人情都值得礼记。 From a1826855ab1618a902a981f663e715d55ee2a213 Mon Sep 17 00:00:00 2001 From: Chad Wuo <41413559+Chadwuo@users.noreply.github.com> Date: Tue, 25 Jul 2023 06:19:06 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=83=20docs:=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=97=A5=E5=8E=86=E5=88=87=E6=8D=A2=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit thanks ya wu --- miniprogram/pages/calendar/index.wxml | 1 + 1 file changed, 1 insertion(+) diff --git a/miniprogram/pages/calendar/index.wxml b/miniprogram/pages/calendar/index.wxml index 642730df..9f59f7d1 100644 --- a/miniprogram/pages/calendar/index.wxml +++ b/miniprogram/pages/calendar/index.wxml @@ -1,4 +1,5 @@ + 左右滑动日历切换月份、年份 \ No newline at end of file From 14ccbd271fc941d2c4772e818fa71dbbe7b825b2 Mon Sep 17 00:00:00 2001 From: Chad Wuo <41413559+Chadwuo@users.noreply.github.com> Date: Fri, 28 Jul 2023 03:50:28 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=8E=88=20perf:=20=E4=BA=B2=E5=8F=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=90=9C=E7=B4=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/alicloud/services/friend.js | 51 ++++++++++++++----------- miniprogram/pages/friend/index.js | 36 ++++++----------- 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/miniprogram/alicloud/services/friend.js b/miniprogram/alicloud/services/friend.js index 6c053c13..940723a4 100644 --- a/miniprogram/alicloud/services/friend.js +++ b/miniprogram/alicloud/services/friend.js @@ -1,4 +1,4 @@ -import pinyin from 'wl-pinyin'; +import pinyin from "wl-pinyin"; const app = getApp(); /** @@ -6,14 +6,21 @@ const app = getApp(); * * @author chadwuo */ -exports.getFriendList = async () => { +exports.getFriendList = async (parameter) => { const db = app.mpserverless.db; const dataScope = app.userDataScope; + + const { searchValue } = parameter || {}; try { - const { result } = await db.collection('friend').find({ - userId: { - $in: dataScope, - }, + const { result } = await db.collection("friend").find({ + $and: [ + { name: { $regex: searchValue } }, + { + userId: { + $in: dataScope, + }, + }, + ], }); return { @@ -36,7 +43,7 @@ exports.getFriendList = async () => { exports.getFriend = async (parameter) => { const db = app.mpserverless.db; try { - const { result } = await db.collection('friend').findOne({ + const { result } = await db.collection("friend").findOne({ _id: parameter._id, }); return { @@ -59,16 +66,16 @@ exports.getFriend = async (parameter) => { exports.getFriendGifts = async (parameter) => { const db = app.mpserverless.db; try { - const { result } = await db.collection('friend').findOne({ + const { result } = await db.collection("friend").findOne({ _id: parameter._id, }); // 送礼集合 - const { result: giftOutList } = await db.collection('gift_out').find({ + const { result: giftOutList } = await db.collection("gift_out").find({ friendId: parameter._id, }); // 收礼集合 const { result: giftReceiveList } = await db - .collection('gift_receive') + .collection("gift_receive") .aggregate([ { $match: { @@ -83,16 +90,16 @@ exports.getFriendGifts = async (parameter) => { { $lookup: { // 左连接 - from: 'book', // 关联到de表 - localField: 'bookId', // 左表关联的字段 - foreignField: '_id', // 右表关联的字段 - as: 'bookInfo', + from: "book", // 关联到de表 + localField: "bookId", // 左表关联的字段 + foreignField: "_id", // 右表关联的字段 + as: "bookInfo", }, }, { $unwind: { // 拆分子数组 - path: '$bookInfo', + path: "$bookInfo", preserveNullAndEmptyArrays: true, // 空的数组也拆分 }, }, @@ -122,7 +129,7 @@ exports.addFriend = async (parameter) => { const userInfo = app.userInfo; const db = app.mpserverless.db; try { - const { result } = await db.collection('friend').insertOne({ + const { result } = await db.collection("friend").insertOne({ userId: userInfo._id, name: parameter.name.trim(), firstLetter: pinyin.getFirstLetter(parameter.name.substr(0, 1)), @@ -149,7 +156,7 @@ exports.addFriend = async (parameter) => { exports.updateFriend = async (parameter) => { const db = app.mpserverless.db; try { - await db.collection('friend').updateOne( + await db.collection("friend").updateOne( { _id: parameter._id, }, @@ -164,7 +171,7 @@ exports.updateFriend = async (parameter) => { ); return { success: true, - data: '', + data: "", }; } catch (e) { return { @@ -183,20 +190,20 @@ exports.deleteFriend = async (parameter) => { const db = app.mpserverless.db; try { // 删除亲友下所有送礼记录 - await db.collection('gift_out').deleteMany({ + await db.collection("gift_out").deleteMany({ friendId: parameter._id, }); // 删除亲友下所有收礼记录 - await db.collection('gift_receive').deleteMany({ + await db.collection("gift_receive").deleteMany({ friendId: parameter._id, }); // 删除亲友 - await db.collection('friend').deleteOne({ + await db.collection("friend").deleteOne({ _id: parameter._id, }); return { success: true, - data: '', + data: "", }; } catch (e) { return { diff --git a/miniprogram/pages/friend/index.js b/miniprogram/pages/friend/index.js index b5839d73..bd5bfb46 100644 --- a/miniprogram/pages/friend/index.js +++ b/miniprogram/pages/friend/index.js @@ -1,5 +1,5 @@ // pages/friend/index.js -const friendService = require('../../alicloud/services/friend'); +const friendService = require("../../alicloud/services/friend"); Page({ /** * 页面的初始数据 @@ -7,7 +7,7 @@ Page({ data: { scrollTop: 0, friendsList: [], - keyword: '', + keyword: "", }, // 监听用户滑动页面事件。 onPageScroll(e) { @@ -19,23 +19,11 @@ Page({ }); }, onSearch() { - if (!this.data.keyword) { - this.loadData(); - return; - } - for (let item of this.data.friendsList) { - item.subItems = item.subItems.filter((x) => - x.name.includes(this.data.keyword) - ); - } - - this.setData({ - friendsList: this.data.friendsList, - }); + this.loadData({ searchValue: this.data.keyword }); }, onFriendClick(e) { wx.navigateTo({ - url: '/pages/friend/details/index', + url: "/pages/friend/details/index", events: { refresh: () => { this.loadData(); @@ -43,7 +31,7 @@ Page({ }, success: function (res) { // 通过 eventChannel 向被打开页面传送数据 - res.eventChannel.emit('acceptDataFromOpenerPage', { + res.eventChannel.emit("acceptDataFromOpenerPage", { friend: e.currentTarget.dataset.friend, }); }, @@ -51,7 +39,7 @@ Page({ }, onAdd() { wx.navigateTo({ - url: '/pages/friend/edit/index', + url: "/pages/friend/edit/index", events: { refresh: () => { this.loadData(); @@ -59,7 +47,7 @@ Page({ }, }); }, - async loadData() { + async loadData(parameter) { this.setData({ friendsList: [], }); @@ -71,10 +59,10 @@ Page({ }); } let noletter = { - alpha: '#', + alpha: "#", subItems: [], }; - const res = await friendService.getFriendList(); + const res = await friendService.getFriendList(parameter); if (res.success) { for (const item of res.data) { const firstLetter = item.firstLetter; @@ -141,9 +129,9 @@ Page({ */ onShareAppMessage() { return { - title: '可能是东半球最好用的人情记账工具', - path: 'pages/start/index', - imageUrl: '/static/img/share.png', + title: "可能是东半球最好用的人情记账工具", + path: "pages/start/index", + imageUrl: "/static/img/share.png", }; }, });