添加组件等
This commit is contained in:
@@ -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<void>((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 });
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
bind:handleLogin="handleLogin">
|
||||
<t-cell title="今日完成工作量" left-icon="chart-bar"
|
||||
custom-style="position: sticky;top: 0;z-index:1;margin-bottom: 24rpx;padding-left: 0" />
|
||||
<!-- <canvas canvas-id="afMCYQMEmXXVAjNQFJvvfxbLSHuxNEOL" id="afMCYQMEmXXVAjNQFJvvfxbLSHuxNEOL"
|
||||
type="2d" class="charts" bindtouchend="tap" /> -->
|
||||
|
||||
<empty-plugin wx:if="{{process_count.length == 0}}" />
|
||||
<block wx:else>
|
||||
|
||||
@@ -45,3 +45,8 @@
|
||||
.seven_process_count_td2 {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* .charts {
|
||||
width: calc(100vw - 24px);
|
||||
height: 68vw;
|
||||
} */
|
||||
|
||||
4
miniprogram/pages/components/date-now/date-now.json
Normal file
4
miniprogram/pages/components/date-now/date-now.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
55
miniprogram/pages/components/date-now/date-now.ts
Normal file
55
miniprogram/pages/components/date-now/date-now.ts
Normal file
@@ -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()]}`,
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
3
miniprogram/pages/components/date-now/date-now.wxml
Normal file
3
miniprogram/pages/components/date-now/date-now.wxml
Normal file
@@ -0,0 +1,3 @@
|
||||
<view class="time-box">
|
||||
<view>{{date}} {{week}}</view>
|
||||
</view>
|
||||
5
miniprogram/pages/components/date-now/date-now.wxss
Normal file
5
miniprogram/pages/components/date-now/date-now.wxss
Normal file
@@ -0,0 +1,5 @@
|
||||
.time-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-bottom: 16rpx;
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
@@ -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<IIsLogin>('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: {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<page-plugin isAuth="{{true}}" loading="{{loading}}" is-login="{{isLogin}}"
|
||||
bind:handleLogin="handleLogin" hasTabBar="1">
|
||||
<!-- <date-now></date-now> -->
|
||||
<view class="block-box">
|
||||
<block wx:for="{{block}}" wx:key="index">
|
||||
<view class="block-item-box" style="background: {{BGColors[index]}};" bind:tap="onBlockNavTo"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { base } from '@/utils/config';
|
||||
import { checkSesskey, loginStatusPage, post } from '@/utils/https';
|
||||
import { Subscribe } from '@/utils/subscribe';
|
||||
import { IIsLogin, Subscribe } from '@/utils/subscribe';
|
||||
import { getStorage, toObject } from '@/utils/util';
|
||||
|
||||
Page({
|
||||
@@ -60,7 +60,7 @@ Page({
|
||||
complete: (res: any) => {
|
||||
if (res.confirm) {
|
||||
post('Applet/loginOut').then(() => {
|
||||
Subscribe.set('isLogin', false);
|
||||
Subscribe.set<IIsLogin>('isLogin', false);
|
||||
this.setData({ isLogin: false });
|
||||
checkSesskey({ showLoading: false, showError: false })
|
||||
.then(() => {})
|
||||
|
||||
@@ -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<IIsLogin>('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<IIsLogin>('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<IIsLogin>('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<IIsLogin>('isLogin', true);
|
||||
that.setData({ isLogin: true, loading: false });
|
||||
that.init?.();
|
||||
})
|
||||
|
||||
@@ -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<T>(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<T>(key: string, functionKey: string, callback: (data: T) => void) {
|
||||
if (!listeners[key]) {
|
||||
listeners[key] = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user