From f9425daab668b4fde9e41d9b2ad40dd4ea9212e9 Mon Sep 17 00:00:00 2001 From: zhengw <247276359@qq.com> Date: Thu, 12 Mar 2026 15:16:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=84=E4=BB=B6=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/pages/base/workload/workload.ts | 85 ++++++++++++++++++- miniprogram/pages/base/workload/workload.wxml | 2 + miniprogram/pages/base/workload/workload.wxss | 5 ++ .../pages/components/date-now/date-now.json | 4 + .../pages/components/date-now/date-now.ts | 55 ++++++++++++ .../pages/components/date-now/date-now.wxml | 3 + .../pages/components/date-now/date-now.wxss | 5 ++ .../components/page-plugin/page-plugin.json | 1 - .../components/page-plugin/page-plugin.ts | 31 ++++--- miniprogram/pages/index/index.json | 1 - miniprogram/pages/index/index.wxml | 1 + miniprogram/pages/my/my.ts | 4 +- miniprogram/utils/https.ts | 10 +-- miniprogram/utils/subscribe.ts | 13 ++- 14 files changed, 193 insertions(+), 27 deletions(-) create mode 100644 miniprogram/pages/components/date-now/date-now.json create mode 100644 miniprogram/pages/components/date-now/date-now.ts create mode 100644 miniprogram/pages/components/date-now/date-now.wxml create mode 100644 miniprogram/pages/components/date-now/date-now.wxss diff --git a/miniprogram/pages/base/workload/workload.ts b/miniprogram/pages/base/workload/workload.ts index 450c7ab..c936e99 100644 --- a/miniprogram/pages/base/workload/workload.ts +++ b/miniprogram/pages/base/workload/workload.ts @@ -1,6 +1,10 @@ import { onPageLoadInitAuth, post } from '@/utils/https'; import { toArray, toNumber } from '@/utils/util'; +// import uCharts from '@/uCharts/u-charts.min.js'; +// const uChartsInstance: any = {}; +// console.log(uCharts); + Page({ /** * 页面的初始数据 @@ -9,6 +13,9 @@ Page({ process_count: [] as any[], seven_process_count: [] as any[], isLogin: false, + // cWidth: 750, + // cHeight: 500, + // pixelRatio: 2, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); @@ -18,8 +25,75 @@ Page({ } }, init() {}, - + // drawCharts(id: string, data: any) { + // const query = wx.createSelectorQuery().in(this); + // query + // .select('#' + id) + // .fields({ node: true, size: true }) + // .exec((res) => { + // if (res[0]) { + // const canvas = res[0].node; + // const ctx = canvas.getContext('2d'); + // canvas.width = res[0].width * this.data.pixelRatio; + // canvas.height = res[0].height * this.data.pixelRatio; + // uChartsInstance[id] = new uCharts({ + // animation: true, + // background: '#FFFFFF', + // canvas2d: true, + // categories: data.categories, + // color: [ + // '#1890FF', + // '#91CB74', + // '#FAC858', + // '#EE6666', + // '#73C0DE', + // '#3CA272', + // '#FC8452', + // '#9A60B4', + // '#ea7ccc', + // ], + // context: ctx, + // extra: { + // column: { type: 'group', width: 30, activeBgColor: '#000000', activeBgOpacity: 0.08 }, + // }, + // height: this.data.cHeight * this.data.pixelRatio, + // legend: {}, + // padding: [15, 15, 0, 5], + // pixelRatio: this.data.pixelRatio, + // series: data.series, + // type: 'column', + // width: this.data.cWidth * this.data.pixelRatio, + // xAxis: { disableGrid: true }, + // yAxis: { + // data: [{ min: 0 }], + // }, + // }); + // } else { + // console.error('[uCharts]: 未获取到 context'); + // } + // }); + // }, + // tap(e: any) { + // uChartsInstance[e.target.id].touchLegend(e); + // uChartsInstance[e.target.id].showToolTip(e); + // }, getList() { + // let res = { + // categories: ['2016', '2017', '2018', '2019', '2020', '2021'], + // series: [ + // { + // name: '目标值', + // data: [35, 36, 31, 33, 13, 34], + // }, + // { + // name: '完成量', + // data: [18, 27, 21, 24, 6, 28], + // }, + // ], + // }; + + // this.drawCharts('afMCYQMEmXXVAjNQFJvvfxbLSHuxNEOL', res); + return new Promise((resolve, reject) => { post('Index/index') .then((res: any) => { @@ -65,7 +139,14 @@ Page({ /** * 生命周期函数--监听页面初次渲染完成 */ - onReady() {}, + onReady() { + // //这里的第一个 750 对应 css .charts 的 width + // const cWidth = wx.getWindowInfo().windowWidth - 24; + // //这里的 500 对应 css .charts 的 height + // const cHeight = wx.getWindowInfo().windowWidth * 0.68; + // const pixelRatio = wx.getWindowInfo().pixelRatio; + // this.setData({ cWidth, cHeight, pixelRatio }); + }, /** * 生命周期函数--监听页面显示 diff --git a/miniprogram/pages/base/workload/workload.wxml b/miniprogram/pages/base/workload/workload.wxml index 1d54777..533109f 100644 --- a/miniprogram/pages/base/workload/workload.wxml +++ b/miniprogram/pages/base/workload/workload.wxml @@ -2,6 +2,8 @@ bind:handleLogin="handleLogin"> + diff --git a/miniprogram/pages/base/workload/workload.wxss b/miniprogram/pages/base/workload/workload.wxss index 5855070..c41e923 100644 --- a/miniprogram/pages/base/workload/workload.wxss +++ b/miniprogram/pages/base/workload/workload.wxss @@ -45,3 +45,8 @@ .seven_process_count_td2 { flex-shrink: 0; } + +/* .charts { + width: calc(100vw - 24px); + height: 68vw; +} */ diff --git a/miniprogram/pages/components/date-now/date-now.json b/miniprogram/pages/components/date-now/date-now.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/miniprogram/pages/components/date-now/date-now.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/components/date-now/date-now.ts b/miniprogram/pages/components/date-now/date-now.ts new file mode 100644 index 0000000..275a9bc --- /dev/null +++ b/miniprogram/pages/components/date-now/date-now.ts @@ -0,0 +1,55 @@ +import { formatTime } from '@/utils/util'; + +Component({ + options: { multipleSlots: true }, + /** + * 组件的属性列表 + */ + properties: {}, + + lifetimes: { + attached() { + // console.log('attached-----'); + }, + detached() { + clearInterval(this.data.timer); + }, + }, + pageLifetimes: { + show() { + clearInterval(this.data.timer); + console.log('show-----'); + this.setDateMsg(); + this.data.timer = setInterval(() => { + this.setDateMsg(); + }, 1000); + }, + hide() { + console.log('hide-----'); + clearInterval(this.data.timer); + }, + }, + + /** + * 组件的初始数据 + */ + data: { + timer: null as any, + date: '', + week: '', + weekArr: ['日', '一', '二', '三', '四', '五', '六'], + }, + + /** + * 组件的方法列表 + */ + methods: { + setDateMsg() { + console.log('ddd'); + this.setData({ + date: formatTime(new Date()), + week: `星期${this.data.weekArr[new Date().getDay()]}`, + }); + }, + }, +}); diff --git a/miniprogram/pages/components/date-now/date-now.wxml b/miniprogram/pages/components/date-now/date-now.wxml new file mode 100644 index 0000000..58b2b82 --- /dev/null +++ b/miniprogram/pages/components/date-now/date-now.wxml @@ -0,0 +1,3 @@ + + {{date}} {{week}} + \ No newline at end of file diff --git a/miniprogram/pages/components/date-now/date-now.wxss b/miniprogram/pages/components/date-now/date-now.wxss new file mode 100644 index 0000000..d414d9b --- /dev/null +++ b/miniprogram/pages/components/date-now/date-now.wxss @@ -0,0 +1,5 @@ +.time-box { + display: flex; + align-items: center; + padding-bottom: 16rpx; +} diff --git a/miniprogram/pages/components/page-plugin/page-plugin.json b/miniprogram/pages/components/page-plugin/page-plugin.json index 32eaf45..d3095ea 100644 --- a/miniprogram/pages/components/page-plugin/page-plugin.json +++ b/miniprogram/pages/components/page-plugin/page-plugin.json @@ -1,7 +1,6 @@ { "component": true, "usingComponents": { - "t-button": "tdesign-miniprogram/button/button", "t-checkbox": "tdesign-miniprogram/checkbox/checkbox", "t-link": "tdesign-miniprogram/link/link", "t-loading": "tdesign-miniprogram/loading/loading", diff --git a/miniprogram/pages/components/page-plugin/page-plugin.ts b/miniprogram/pages/components/page-plugin/page-plugin.ts index 9d386a0..ee47484 100644 --- a/miniprogram/pages/components/page-plugin/page-plugin.ts +++ b/miniprogram/pages/components/page-plugin/page-plugin.ts @@ -1,7 +1,7 @@ import { base, defaultAvatarUrl } from '@/utils/config'; import { login } from '@/utils/https'; -import { Subscribe } from '@/utils/subscribe'; -import { getCurrentPageRoute, isArray } from '@/utils/util'; +import { IIsLogin, Subscribe } from '@/utils/subscribe'; +import { getCurrentPageRoute, getStorage, isArray, setStorage } from '@/utils/util'; // import { IStorage } from "@/utils/storage"; // const app = getApp(); @@ -17,18 +17,21 @@ Component({ hasTabBar: null, }, - attached() { - // this.setData({ isLogin: getStorage('isLogin') == 1 }); - // console.log('attached'); - Subscribe.on('isLogin', getCurrentPageRoute(), (data: any) => { - // console.log(data); - this.setData({ isLogin: data, loading: false }); - // console.log('监听到 isLogin 变化:'); - }); - }, - detached() { - // console.log('detached'); - Subscribe.off('isLogin', getCurrentPageRoute()); + lifetimes: { + attached() { + this.setData({ isLogin: getStorage('isLogin') == 1 }); + // console.log('attached'); + Subscribe.on('isLogin', getCurrentPageRoute(), (data) => { + // console.log(data); + setStorage('isLogin', data ? 1 : 0); + this.setData({ isLogin: data, loading: false }); + // console.log('监听到 isLogin 变化:'); + }); + }, + detached() { + // console.log('detached'); + Subscribe.off('isLogin', getCurrentPageRoute()); + }, }, data: { diff --git a/miniprogram/pages/index/index.json b/miniprogram/pages/index/index.json index dbb4bf4..3dff4b8 100644 --- a/miniprogram/pages/index/index.json +++ b/miniprogram/pages/index/index.json @@ -1,6 +1,5 @@ { "usingComponents": { - "t-button": "tdesign-miniprogram/button/button", "t-icon": "tdesign-miniprogram/icon/icon", "tab-bar-plugin": "/pages/components/tab-bar-plugin/tab-bar-plugin", "pagination-plugin": "/pages/components/pagination-plugin/pagination-plugin", diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml index 8c5a8e4..32fc373 100644 --- a/miniprogram/pages/index/index.wxml +++ b/miniprogram/pages/index/index.wxml @@ -1,5 +1,6 @@ + { if (res.confirm) { post('Applet/loginOut').then(() => { - Subscribe.set('isLogin', false); + Subscribe.set('isLogin', false); this.setData({ isLogin: false }); checkSesskey({ showLoading: false, showError: false }) .then(() => {}) diff --git a/miniprogram/utils/https.ts b/miniprogram/utils/https.ts index 33c3444..6fd02bb 100644 --- a/miniprogram/utils/https.ts +++ b/miniprogram/utils/https.ts @@ -3,7 +3,7 @@ * YangXB 2021.11.24 * */ import { base, http } from './config'; -import { Subscribe } from './subscribe'; +import { IIsLogin, Subscribe } from './subscribe'; import { getStorage, isArray, setStorage, toArray, toastError } from './util'; /** * 请求 @@ -48,7 +48,7 @@ const request = (url: string, options: any, config = { showLoading: true, showEr wx.showToast({ title: request.data.err_msg, icon: 'none' }); } if (request.data.err_code == 110000) { - Subscribe.set('isLogin', false); + Subscribe.set('isLogin', false); // const currentPage = getCurrentPage(); // console.log(currentPage); @@ -147,7 +147,7 @@ export const loginStatus = () => { setStorage('auth_info', res.auth_info); setStorage('session_id', res.session_id); getUsersConfigList(); - Subscribe.set('isLogin', true); + Subscribe.set('isLogin', true); resolve(res); }) .catch((err: any) => { @@ -157,7 +157,7 @@ export const loginStatus = () => { post('Applet/loginOut').then(() => { checkSesskey({ showLoading: false, showError: false }) .then(() => { - Subscribe.set('isLogin', false); + Subscribe.set('isLogin', false); }) .catch((err) => { console.log('checkSesskey', err); @@ -204,7 +204,7 @@ export const onPageLoadInitAuth = ( initFun() .then((_res) => { // console.log('onPageLoadInitAuth', res); - Subscribe.set('isLogin', true); + Subscribe.set('isLogin', true); that.setData({ isLogin: true, loading: false }); that.init?.(); }) diff --git a/miniprogram/utils/subscribe.ts b/miniprogram/utils/subscribe.ts index 6f7d76c..a290e37 100644 --- a/miniprogram/utils/subscribe.ts +++ b/miniprogram/utils/subscribe.ts @@ -18,13 +18,18 @@ function triggerEvent(key: string, data: any) { type IFun = Function & { $$functionKey?: string }; +/** + * isLogin 的数据类型 + */ +export type IIsLogin = boolean; + export const Subscribe = { /** * 设置 * @param key 订阅变量的key * @param value 值 */ - set(key: string, value: any) { + set(key: string, value: T) { // 1. 执行原有的存储操作 // setStorage(key, value); // 2. 触发自定义事件,通知订阅者 @@ -35,6 +40,10 @@ export const Subscribe = { // return getStorage(key); // }, + /** + * 批量移除订阅 + * @param key 订阅变量的key + */ remove(key: string) { triggerEvent(key, null); // 或者触发一个 'remove' 事件 }, @@ -45,7 +54,7 @@ export const Subscribe = { * @param functionKey 唯一的函数key(用于取消订阅的) * @param callback 回调函数 */ - on(key: string, functionKey: string, callback: (data: any) => void) { + on(key: string, functionKey: string, callback: (data: T) => void) { if (!listeners[key]) { listeners[key] = []; }