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

@ -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>