Skip to content

Commit

Permalink
perf(*): 优化校园卡使用体验,yxy 绑定添加 beta 标徽 (#30)
Browse files Browse the repository at this point in the history
* fix(electricity): change property `surplus` to `soc` of response

* fix(school-card): disable show modal when requset error in home page

* chore(bind): add beta badge to yxy bind item
  • Loading branch information
j10ccc authored Feb 9, 2023
1 parent 2211f9a commit 168dc28
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/components/ElectricityQuickView/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<view class="text-wrapper" v-if="!loading">
<text> 寝室剩余电费 </text>
<text :class="isUrgent ? 'dangerous' : 'normal'">
{{ balanceData?.data.surplus || 0 }}
{{ balanceData?.data.soc || 0 }}
</text>
<text> 度 </text>
</view>
Expand All @@ -35,16 +35,16 @@ function nav2electricity() {
const { data: balanceData, loading, error } = useRequest(
YxyService.queryBalance, {
onSuccess: (res) => {
if (res.data.data?.surplus) {
store.commit("setBalance",res.data.data.surplus);
if (res.data.data?.soc) {
store.commit("setBalance",res.data.data.soc);
} else throw new Error();
}
}
);
const isUrgent = computed(() => {
if (balanceData.value)
return balanceData.value.data.surplus < 20;
return balanceData.value.data.soc < 20;
else
return false;
});
Expand Down
13 changes: 2 additions & 11 deletions src/components/SchoolCardQuickView/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,9 @@ const { error } = useRequest(YxyService.querySchoolCardBalance, {
if (Number.isFinite(parseFloat(res.data.data)))
store.commit("setCardBalance", res.data.data);
else throw new Error("无效余额值");
} else if (res.data.code === 200514) {
Taro.showModal({
title: "查询余额失败",
content: res.data.msg,
confirmText: "重新登录",
success: (res) => {
if (res.confirm)
Taro.navigateTo({ url: "/pages/bind/index" });
}
});
} else {
throw new Error(res.data.msg);
}
else throw new Error(res.data.msg);
},
onError: (error) => {
if (!(error instanceof Error)) return `查询校园卡余额\r\n${error.errMsg}`;
Expand Down
23 changes: 23 additions & 0 deletions src/pages/bind/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
@include radius;
background-color: var(--wjh-color-week);
color: var(--wjh-color-white);

.wjh-list-item-content-main {
align-items: center;
}
}

.binded {
Expand All @@ -47,3 +51,22 @@
}
}
}

.beta-badge::before {
position: absolute;
content: "beta";
top: -1rem;
right: 0;
padding: 4Px 8Px;
line-height: 100%;
background-color: var(--wjh-color-red);
border-radius: 16Px;
}

.badge {
font-size: .8rem;
padding: 4Px 8Px;
line-height: 100%;
background-color: var(--wjh-color-red);
border-radius: 16Px;
}
5 changes: 3 additions & 2 deletions src/pages/bind/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
<w-list class="bind-list">
<w-list-item
:extra="user.isBindYXY ? '已绑定' : '未绑定'"
:class="{ binded: user.isBindYXY }"
:class="[{ binded: user.isBindYXY }]"
arrow="down"
@tap="renderForm('yxy')"
>
一卡通账号
<text> 一卡通账号 </text>
<view class="badge">测试</view>
</w-list-item>
</w-list>
</card>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/electricity/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ useRequest(YxyService.queryBalance, {
store.commit("setElectricityStore", {
roomName: response.data.data.display_room_name,
roomCode: response.data.data.room_code,
balance: response.data.data.surplus
balance: response.data.data.soc
});
} else {
throw new Error(response.data.msg || response.errMsg);
Expand Down
4 changes: 2 additions & 2 deletions src/services/services/yxyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export default class YxyService {
display_room_name: string;
md_name: string;
room_code: string;
surplus: number; //kwh
surplus_amount: number; // rmb
soc: number; //kwh
soc_amount: number; // rmb
}>(
api.electricity.balance, {
method: "GET",
Expand Down

0 comments on commit 168dc28

Please sign in to comment.