This commit is contained in:
quantulr
2023-08-31 16:24:37 +08:00
parent 0288146b0d
commit 5bbe958729
32 changed files with 317 additions and 105 deletions

View File

@ -11,7 +11,10 @@ export const login = (data: LoginForm) =>
data,
});
export const getInfo = () =>
export const getInfo = (token?: string) =>
httpClient.request({
url: "/getInfo",
header: {
Authorization: token ? `Bearer ${token}` : undefined,
},
});

View File

@ -1,7 +1,6 @@
{
"pages": [
"pages/index/index",
"pages/logs/logs",
"pages/add-finance/add-finance",
"pages/login/login",
"pages/stock/stock",
@ -45,5 +44,6 @@
"t-tab-panel": "tdesign-miniprogram/tab-panel/tab-panel",
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group"
},
"lazyCodeLoading": "requiredComponents",
"sitemapLocation": "sitemap.json"
}

View File

@ -1,17 +1,26 @@
import { getToken } from "./utils/settings";
import { getInfo } from "./api/login";
import { getToken, getUserInfo } from "./utils/settings";
// app.ts
App<IAppOption>({
globalData: {
authToken: undefined,
permissions:[]
permissions: undefined,
user: undefined,
},
loadUserInfo(token: string) {
getInfo(token).then((resp: any) => {
const { user, permissions } = resp;
this.globalData.user = user;
this.globalData.permissions = permissions;
console.log(this.globalData);
});
},
onLaunch() {
// 展示本地存储能力
const logs = wx.getStorageSync("logs") || [];
logs.unshift(Date.now());
wx.setStorageSync("logs", logs);
this.globalData.authToken = getToken();
const token = getToken();
this.globalData.authToken = token;
this.loadUserInfo(token);
// 登录
wx.login({
success: (res) => {

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -1,7 +1,9 @@
<!--components/statistics-card/index.wxml-->
<wxs module="number" src="../../utils/number.wxs" />
<view class="statistcs-card">
<view wx:for="{{statisticsData}}" wx:key="key" wx:for-item="value" class="statistcs-item">
<view class="value">{{value.value}}</view>
<view class="value" wx:if="{{value.type=='money'}}">{{number.formatAmount(value.value)}}万元</view>
<view class="value" wx:else="">{{value.value}}</view>
<view class="title">{{value.label}}</view>
</view>
</view>

View File

@ -1,6 +1,7 @@
import Message from "tdesign-miniprogram/message/index";
import { getDict } from "../../api/dict";
import { addFinance, getFinanceInfo, updateFinance } from "../../api/finance";
import { getInfo } from "../../api/login";
// pages/add-affairs/add-affairs.ts
const dayjs = require("dayjs");
@ -9,6 +10,7 @@ Page({
* 页面的初始数据
*/
data: {
permissions: [],
defaultTime: dayjs(dayjs().format("YYYY-MM-DD")).valueOf(),
types: [],
form: {
@ -56,6 +58,23 @@ Page({
[`form.date`]: e.detail.value,
});
},
loadUserInfo() {
const permissions = getApp().globalData.permissions;
if (permissions) {
this.setData({
permissions,
});
} else {
const token = getApp().globalData.authToken;
getInfo(token).then((resp: any) => {
this.setData({
permissions: resp.permissions,
});
getApp().globalData.permissions = resp.permissions;
});
}
},
getTypeLabel(dictValue: string) {
// @ts-ignore
return this.data.types.find((item: any) => item.value === dictValue)?.label;
@ -117,6 +136,7 @@ Page({
}
}
},
handleSubmitFinance() {
const { form } = this.data;
const result = this.validate();
@ -208,6 +228,7 @@ Page({
this.getFinanceDetail(option.financeId);
}
this.getTypeOptions();
this.loadUserInfo();
},
/**

View File

@ -2,6 +2,7 @@
<t-message id="t-message" />
<wxs module="times" src="../../utils/time.wxs" />
<wxs module="dict" src="../../utils/dict.wxs" />
<wxs module="utils" src="../../utils/utils.wxs" />
<view class="add-affairs">
<view class="add-affairs-form">
<t-input label="事项" bind:change="onChange" data-field="event" value="{{form.event}}" align="right" placeholder="请输入事项"></t-input>
@ -10,14 +11,13 @@
<t-input label="对方账户" bind:change="onChange" data-field="oppositeCompany" value="{{form.oppositeCompany}}" align="right" placeholder="请输入对方账户"></t-input>
<t-input label="金额" type="number" bind:change="onChange" data-field="amount" value="{{form.amount}}" align="right" placeholder="请输入金额"></t-input>
</view>
<view class="submit-button">
<view wx:if="{{utils.hasPermission('finance:detail:edit', permissions)}}" class="submit-button">
<t-button bind:tap="handleSubmitFinance" theme="primary" block>确认提交</t-button>
</view>
<!-- 年月日 -->
<t-date-time-picker title="选择日期" visible="{{dateVisible}}" mode="date" defaultValue="{{form.date || defaultTime}}" format="YYYY-MM-DD HH:mm:ss" bindchange="handleConfirmTime" bindcancel="hideTimePicker" />
<t-picker visible="{{pickerVisible}}" value="{{form.type}}" data-key="type" title="选择类别" cancelBtn="取消" confirmBtn="确认" bindchange="onPickerChange" bindpick="onColumnChange" bindcancel="onPickerCancel">
<t-picker-item options="{{types}}" />
</t-picker>

View File

@ -1,11 +1,8 @@
{
"usingComponents": {
"t-popup": "tdesign-miniprogram/popup/popup",
"t-input": "tdesign-miniprogram/input/input",
"t-upload": "tdesign-miniprogram/upload/upload",
"t-picker": "tdesign-miniprogram/picker/picker",
"t-cascader": "tdesign-miniprogram/cascader/cascader",
"t-tree-select": "tdesign-miniprogram/tree-select/tree-select",
"t-picker-item": "tdesign-miniprogram/picker-item/picker-item",
"t-date-time-picker": "tdesign-miniprogram/date-time-picker/date-time-picker"
}

View File

@ -70,6 +70,8 @@ Page({
[`form.${field}`]: e.detail.value,
});
if (field === "total") {
console.log(e.detail);
if (
parseInt(e.detail.value) > this.data.stockLimit &&
this.data.form.type == 2

View File

@ -24,7 +24,7 @@
</t-upload>
</view>
</view>
<t-input label="数量" type="number" bind:change="onChange" data-field="total" value="{{form.total}}" placeholder="请输入数量" tips="{{totalErrMsg}}" status="{{totalErrMsg?'error':''}}" />
<t-input label="数量" align="right" type="number" bind:change="onChange" data-field="total" value="{{form.total}}" placeholder="请输入数量" tips="{{totalErrMsg}}" status="{{totalErrMsg?'error':''}}" />
</view>
<view class="submit-button">
<t-button bind:tap="handleSubmitStock" theme="primary" block>确认提交</t-button>

View File

@ -1,9 +1,9 @@
{
"usingComponents": {
"t-fab": "tdesign-miniprogram/fab/fab",
"t-collapse": "tdesign-miniprogram/collapse/collapse",
"t-collapse-panel": "tdesign-miniprogram/collapse-panel/collapse-panel",
"statistics-card": "/components/statistics-card"
"t-swipe-cell": "tdesign-miniprogram/swipe-cell/swipe-cell",
"statistics-card": "/components/statistics-card",
"t-dialog": "tdesign-miniprogram/dialog/dialog"
},
"enablePullDownRefresh": true
}

View File

@ -85,6 +85,37 @@ page {
animation: shake-crazy 1s infinite linear;
}
}
.t-swipe-cell__right {
view {
height: 100%;
}
}
.finance-list {
.left-icon {
width: 48rpx;
height: 48rpx;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
}
.btn-wrapper {
// height: 100%;
.btn {
display: inline-flex;
justify-content: center;
align-items: center;
width: 140rpx;
height: 100%;
color: white;
}
.delete-btn {
background-color: #e34d59;
}
}
}
.to-login {
height: 40vh;
display: flex;

View File

@ -4,6 +4,7 @@ import {
getFinanceList,
getStatistics,
} from "../../api/finance";
import { getInfo } from "../../api/login";
// pages/index/index.ts
Page({
@ -11,29 +12,35 @@ Page({
* 页面的初始数据
*/
data: {
showConfirmDelete: false,
permissions: [],
queryParams: {
pageNum: 1,
pageSize: 10,
},
authToken: undefined,
authToken: null,
statistics: {
amount: {
label: "账户余额",
value: 0,
type: "money",
},
income: {
label: "当月入账",
value: 0,
type: "money",
},
expenditure: {
label: "当月出账",
value: 0,
type: "money",
},
},
loading: false,
total: 0,
completed: false,
deleteIndex: -1,
deleteId: null,
list: [],
types: [],
},
@ -71,9 +78,9 @@ Page({
async getStatisticsDetail() {
const resp: any = await getStatistics();
this.setData({
['statistics.amount.value']: resp.data.amount,
['statistics.income.value']: resp.data.income,
['statistics.expenditure.value']: resp.data.expenditure,
["statistics.amount.value"]: resp.data.amount,
["statistics.income.value"]: resp.data.income,
["statistics.expenditure.value"]: resp.data.expenditure,
});
},
handleAddAffairs() {
@ -102,9 +109,26 @@ Page({
});
});
},
showDeleteDialog(e: any) {
console.log(e.currentTarget.dataset);
const { financeId } = e.currentTarget.dataset;
this.setData({
showConfirmDelete: true,
deleteId: financeId,
});
},
closeDialog() {
this.setData({
showConfirmDelete: false,
});
},
handleLongTap(e: any) {
console.log(e);
const { deleteIndex } = this.data;
const { deleteIndex, permissions } = this.data;
// @ts-ignore
if (!permissions.includes("finance:detail:remove")) {
return;
}
const index = parseInt(e.currentTarget.dataset.index);
let resultIndex;
@ -117,12 +141,14 @@ Page({
deleteIndex: resultIndex,
});
},
handleDeleteFinance(e: any) {
const { financeId } = e.currentTarget.dataset;
deleteFinance(financeId).then(() => {
handleDeleteFinance() {
const { deleteId } = this.data;
if (!deleteId) return;
// @ts-ignore
deleteFinance(deleteId).then(() => {
const { list } = this.data;
this.setData({
list: list.filter((el: any) => el.financeId !== financeId),
list: list.filter((el: any) => el.financeId !== deleteId),
deleteIndex: -1,
});
});
@ -140,6 +166,23 @@ Page({
url: "/pages/login/login",
});
},
loadUserInfo() {
const permissions = getApp().globalData.permissions;
if (permissions) {
this.setData({
permissions,
});
} else {
const token = getApp().globalData.authToken;
getInfo(token).then((resp: any) => {
this.setData({
permissions: resp.permissions,
});
getApp().globalData.permissions = resp.permissions;
});
}
},
loadPageData() {
const authToken = getApp().globalData.authToken;
this.setData({
@ -165,6 +208,7 @@ Page({
*/
onShow() {
this.loadPageData();
this.loadUserInfo();
},
/**

View File

@ -2,11 +2,28 @@
<t-message id="t-message" />
<wxs module="times" src="../../utils/time.wxs" />
<wxs module="dict" src="../../utils/dict.wxs" />
<wxs module="utils" src="../../utils/utils.wxs" />
<view class="home-page">
<t-fab class="float-button" icon="add" aria-label="增加" bind:click="handleAddAffairs" />
<t-fab wx:if="{{utils.hasPermission('finance:detail:add', permissions)}}" class="float-button" icon="add" aria-label="增加" bind:click="handleAddAffairs" />
<statistics-card statistics-data="{{statistics}}" />
<view class="divider"></view>
<view wx:if="{{authToken}}" class="list">
<view wx:if="{{authToken}}" class="finance-list">
<t-cell-group theme="card">
<t-swipe-cell wx:for="{{list}}" wx:key="account" data-finance-id="{{item.financeId}}">
<t-cell bind:tap="handleUpdateFinance" data-finance-id="{{item.financeId}}" title="{{item.event}}" hover>
<view class="left-icon" slot="left-icon" style="background: {{item.type=='finance_type_income'?'#38a169':item.type=='finance_type_expenditure'?'#dd6b20':'transparent'}};">
<text>{{item.type=='finance_type_income'?'入':item.type=='finance_type_expenditure'?'出':''}}</text>
</view>
<view slot="description">{{times.formatDate(item.date) || "-"}} | {{item.oppositeCompany}}</view>
<view slot="note" style="color: {{item.type=='finance_type_income'?'#38a169':item.type=='finance_type_expenditure'?'#dd6b20':'transparent'}};">{{item.type=='finance_type_income'?'+':item.type=='finance_type_expenditure'?'-':''}}{{item.amount}}</view>
</t-cell>
<view slot="right" class="btn-wrapper" data-finance-id="{{item.financeId}}" bind:tap="showDeleteDialog">
<view class="btn delete-btn">删除</view>
</view>
</t-swipe-cell>
</t-cell-group>
</view>
<!-- <view wx:if="{{authToken}}" class="list">
<view wx:for="{{list}}" wx:key="account" data-finance-id="{{item.financeId}}" bind:longpress="handleLongTap" data-index="{{index}}" bind:tap="handleUpdateFinance" class="{{ index === deleteIndex ? 'card shake' : 'card' }}">
<view class="field">
<view class="indicator"></view>
@ -45,8 +62,10 @@
</view>
<t-icon wx:if="{{index === deleteIndex}}" name="close-circle-filled" color="red" size="56rpx" data-finance-id="{{item.financeId}}" data-index="{{index}}" catchtap="handleDeleteFinance" class="close-button"></t-icon>
</view>
</view>
</view> -->
<view wx:else class="to-login">
<t-button icon="login" theme="primary" bind:tap="toLogin">前往登录</t-button>
</view>
<t-dialog visible="{{showConfirmDelete}}" title="确认删除" confirm-btn="确认" cancel-btn="取消" bind:confirm="handleDeleteFinance" bind:cancel="closeDialog" />
</view>

View File

@ -1,3 +1,9 @@
{
"usingComponents": {}
"usingComponents": {
"t-navbar": "tdesign-miniprogram/navbar/navbar",
"t-image": "tdesign-miniprogram/image/image",
"t-avatar": "tdesign-miniprogram/avatar/avatar"
},
"navigationBarTitleText": "个人中心",
"navigationStyle": "custom"
}

View File

@ -1,11 +1,56 @@
/* pages/login/login.wxss */
.login{
height: 100vh;
.t-navbar__placeholder {
--td-navbar-padding-top: 0;
--td-navbar-height: 0;
}
.t-navbar__content {
--td-navbar-bg-color: rgba(0, 0, 0, 0);
}
.nav-title {
color: #ffffff;
}
.login-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
aspect-ratio: 3/2;
position: relative;
overflow: hidden;
border-radius: 0 0 50% 50% / 0 0 4% 4%;
.login-bg {
position: absolute;
left: 0;
top: 0;
}
.avatar_login {
margin-left: 64rpx;
display: flex;
align-items: center;
.login-button {
margin-top: 60rpx;
margin-left: 24rpx;
&.t-button--primary {
--td-button-primary-text-color: #ffffff;
}
}
}
.vip-card {
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 80%;
height: 80rpx;
background-color: #ccb88d;
border-radius: 24rpx 24rpx 0 0;
color: #ffffff;
display: flex;
align-items: center;
text {
margin-left: 32rpx;
}
}
}
.options-container {
margin-top: 32rpx;
}

View File

@ -1,4 +1,4 @@
import { login } from "../../api/login";
import { getInfo, login } from "../../api/login";
import { setToken } from "../../utils/settings";
// pages/login/login.ts
@ -7,25 +7,28 @@ Page({
* 页面的初始数据
*/
data: {
authToken: undefined,
authToken: null,
},
loginWithWeChat(e: any) {
login({
code: e.detail.code,
}).then((response: any) => {
this.setData({
authToken: response.token,
});
setToken(response.token);
// setToken(response.token);
wx.switchTab({
url: "/pages/index/index",
getInfo(response.token).then((resp: any) => {
getApp().globalData.permissions = resp.permissions;
});
});
},
handleLogout() {
this.setData({
authToken: undefined
})
setToken(undefined)
authToken: null,
});
getApp().globalData.permissions = undefined;
setToken(undefined);
},
/**
* 生命周期函数--监听页面加载

View File

@ -1,7 +1,22 @@
<!--pages/login/login.wxml-->
<t-message id="t-message" />
<view class="login">
<t-icon name="user-arrow-up" size="72rpx" color="#0052d9"></t-icon>
<t-button wx:if="{{authToken}}" class="login-button" shape="round" theme="primary">退出登录</t-button>
<t-button wx:else class="login-button" shape="round" open-type="getPhoneNumber" bindgetphonenumber="loginWithWeChat" theme="primary">手机号快捷登录</t-button>
<view class="block">
<t-navbar title="个人中心" t-class="nav" t-class-title="nav-title" />
</view>
<view class="login-container">
<t-image class="login-bg" width="100%" height="100%" src="/assets/login_bg.jpg" />
<view class="avatar_login">
<t-avatar icon="user" />
<t-button wx:if="{{!authToken}}" open-type="getPhoneNumber" bindgetphonenumber="loginWithWeChat" class="login-button" size="medium" theme="primary" variant="text">登录</t-button>
</view>
<view class="vip-card">
<text>中科九章管理层</text>
</view>
</view>
<view class="options-container">
<t-cell-group theme="card">
<t-cell title="个人设置" leftIcon="setting" hover arrow />
<t-cell title="意见反馈" leftIcon="chat-bubble-smile" hover arrow />
<t-cell wx:if="{{authToken}}" title="退出登录" bind:tap="handleLogout" leftIcon="logout" hover arrow />
</t-cell-group>
</view>

View File

@ -1,6 +0,0 @@
{
"navigationBarTitleText": "查看启动日志",
"usingComponents": {
"t-divider": "tdesign-miniprogram/divider/divider"
}
}

View File

@ -1 +0,0 @@
/* pages/logs/logs.wxss */

View File

@ -1,19 +0,0 @@
// logs.ts
// const util = require('../../utils/util.js')
import { formatTime } from '../../utils/util'
Page({
data: {
logs: [],
},
onLoad() {
this.setData({
logs: (wx.getStorageSync('logs') || []).map((log: string) => {
return {
date: formatTime(new Date(log)),
timeStamp: log
}
}),
})
},
})

View File

@ -1,6 +0,0 @@
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:key="timeStamp" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log.date}}</text>
</block>
</view>

View File

@ -1,8 +0,0 @@
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}

View File

@ -7,6 +7,8 @@ page{
}
.stock-tabs {
margin: 16rpx 32rpx 0;
border-radius: 18rpx;
overflow: hidden;
}
.stock-list {
padding: 16rpx 0 32rpx;

View File

@ -1,3 +1,4 @@
import { getInfo } from "../../api/login";
import { stockLogList, stockStatistics, storageList } from "../../api/stock";
import httpClient from "../../utils/request";
@ -7,6 +8,7 @@ Page({
* 页面的初始数据
*/
data: {
permissions: [],
authToken: undefined,
stockType: 0, // 库存类型
// 统计数据
@ -262,13 +264,30 @@ Page({
url: `/pages/add-stock/add-stock?type=${stockType}`,
});
},
handleUpdateStock() {},
loadUserInfo() {
const permissions = getApp().globalData.permissions;
if (permissions) {
this.setData({
permissions,
});
} else {
const token = getApp().globalData.authToken;
getInfo(token).then((resp: any) => {
this.setData({
permissions: resp.permissions,
});
getApp().globalData.permissions = resp.permissions;
});
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
this.loadData();
this.loadUserInfo();
},
/**
* 刷新此页面

View File

@ -1,14 +1,18 @@
<!--pages/stock/stock.wxml-->
<!-- 产品库存管理 -->
<t-message id="t-message" />
<wxs module="times" src="../../utils/time.wxs" />
<wxs module="utils" src="../../utils/utils.wxs" />
<statistics-card statistics-data="{{statisticsData}}" />
<t-tabs class="stock-tabs" defaultValue="{{0}}" value="{{stockType}}" bind:change="onTabsChange" theme="tag">
<view class="stock-tabs">
<t-tabs defaultValue="{{0}}" value="{{stockType}}" bind:change="onTabsChange" theme="tag">
<t-tab-panel label="库存" value="{{0}}" />
<t-tab-panel label="入库" value="{{1}}" />
<t-tab-panel label="出库" value="{{2}}" />
</t-tabs>
</view>
<view class="stock-list">
<t-fab wx:if="{{stockType > 0}}" class="float-button" icon="add" aria-label="增加" bind:click="handleAddStock"></t-fab>
<t-fab wx:if="{{stockType > 0 && utils.hasPermission('product:product:add', permissions)}}" class="float-button" icon="add" aria-label="增加" bind:click="handleAddStock"></t-fab>
<view hidden="{{stockType!=0}}" class="scroll-container">
<view class="grid">
<view wx:for="{{storageList}}" wx:key="specId" class="card">

View File

@ -0,0 +1,7 @@
function formatAmount(amount) {
return (amount / 10000).toFixed(2);
}
module.exports = {
formatAmount: formatAmount,
};

View File

@ -46,9 +46,11 @@ class HttpClient {
url = `${this.baseUrl}${req.url}${paramsString}`;
}
const app = getApp();
const header: any = req.header ?? {};
if (!authWhitelist.includes(req.url)) {
header.Authorization = `Bearer ${app.globalData.authToken}`;
if (!authWhitelist.includes(req.url) && !header.Authorization) {
header.Authorization = `Bearer ${app?.globalData?.authToken}`;
}
return new Promise(function (resolve, reject) {
wx.request({

View File

@ -1,8 +1,10 @@
import { getInfo } from "../api/login";
export const setToken = (token?: string) => {
getApp().globalData.authToken = token;
wx.setStorage({
key: "auth-token",
data: token,
data: token ?? "",
});
};
// 如果不存在token则跳转到身份选择页面
@ -17,7 +19,17 @@ export const requiredAuth = () => {
});
}
};
export const getToken = () => {
const token = wx.getStorageSync("auth-token");
return token;
};
export const getUserInfo = async () => {
const { userInfo } = getApp().globalData;
if (!userInfo) {
const token = getApp().globalData.authToken;
const resp = await getInfo(token);
return resp;
}
};

View File

@ -0,0 +1,7 @@
function hasPermission(permission, permissions) {
return permissions.indexOf(permission) != -1;
}
module.exports = {
hasPermission: hasPermission,
};

View File

@ -14,7 +14,7 @@
},
"coverView": false,
"postcss": false,
"minified": false,
"minified": true,
"enhance": true,
"showShadowRootInWxmlPanel": false,
"packNpmRelationList": [],

2
typings/index.d.ts vendored
View File

@ -5,6 +5,8 @@ interface IAppOption {
userInfo?: WechatMiniprogram.UserInfo;
authToken?: string;
permissions?: [];
user?: Object;
};
loadUserInfo: (token: string) => void;
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback;
}