Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

状态管理从 vuex 迁移至 pinia #115

Draft
wants to merge 97 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
5c0b36d
perf(store): 接入 pinia 准备工作 (#114)
j10ccc Oct 10, 2024
7757ca9
Merge remote-tracking branch 'zjutjh/master' into refactor/state-mana…
j10ccc Oct 12, 2024
619fd2c
style(app): make eslint happy
j10ccc Oct 12, 2024
1487388
chore(canteen): deprecate canteen flow page (#137)
j10ccc Oct 19, 2024
9a8c212
feat(service): new request implementation
j10ccc Oct 15, 2024
0bc82a1
feat(request): define error for mp
j10ccc Oct 16, 2024
f66f34a
fix(request): handle case for missing server resp
j10ccc Oct 17, 2024
82e4e51
feat(request): new useRequest hook
j10ccc Oct 17, 2024
0b12ff3
feat(request): request for auth
j10ccc Oct 18, 2024
f028cfc
chore(project-config): enable transform to es5
j10ccc Oct 18, 2024
246a1c6
fix(cookie): return new cookie after refresh
j10ccc Oct 18, 2024
98caa7d
fix(cookie): handle exception when refresh cookie
j10ccc Oct 18, 2024
3ae3fc0
chore(request): declare deprecated for old logic
j10ccc Oct 20, 2024
abd4d14
refactor(store): 使用pinia重构SystemStore和ServiceStore/index.ts
xixiIBN5100 Oct 18, 2024
765decb
perf(store): 删除了mainStore封装
xixiIBN5100 Oct 19, 2024
6c58664
refactor(store):使用pinia重构announcementStore
xixiIBN5100 Oct 19, 2024
88d2e47
refactor(store):使用pinia重构cardStore
xixiIBN5100 Oct 20, 2024
26433c1
refactor(store):优化userService中的store.commit
xixiIBN5100 Oct 20, 2024
ab805bb
refactor(store): 使用pinia重构zfStore
xixiIBN5100 Oct 20, 2024
5b86273
feat(store): 添加仓库入口
xixiIBN5100 Oct 20, 2024
b872186
chore(canteen): deprecate canteen flow page (#137)
j10ccc Oct 19, 2024
06f7206
refactor(store): 使用pinia重构scoreStore
xixiIBN5100 Oct 20, 2024
d4e1ff6
refactor(store): 使用pinia重构userStore
xixiIBN5100 Oct 20, 2024
5b5e0d4
refactor(store): 在zfService中使用pinia
xixiIBN5100 Oct 20, 2024
47131d7
refactor(store): 在yxyService中使用pinia
xixiIBN5100 Oct 20, 2024
a189d2b
Merge branch 'refactor/state-manage-hookify' into refactor/general-se…
j10ccc Oct 20, 2024
0e13a99
Merge pull request #139 from j10ccc/refactor/general-service
j10ccc Oct 20, 2024
02684e9
Merge pull request #138 from j10ccc/feat/new-request-function
j10ccc Oct 22, 2024
6e11aa2
fix(request): declare type for giving value to ref (#141)
j10ccc Oct 22, 2024
1623d75
fix(request): handle unexpected case (#142)
j10ccc Oct 23, 2024
34e4988
Merge branch 'master' into refactor/state-manage-hookify
j10ccc Oct 24, 2024
0c82ed1
fix(badge): pass content by slot
j10ccc Oct 25, 2024
43d15cc
chore(deps): remove vuex, add types
j10ccc Oct 26, 2024
03dbe14
fix(request): replace process with import
j10ccc Oct 26, 2024
7d10499
refactor(user): new activate logic
j10ccc Oct 26, 2024
b08ce59
refactor(user): place user related logic in hook
j10ccc Oct 26, 2024
c577385
fix(entry): remove login after app mount
j10ccc Oct 26, 2024
1177062
refactor(system): get system related data in new way
j10ccc Oct 26, 2024
f0bf38b
refactor(new-feature): migrate notification to new features
j10ccc Oct 26, 2024
d3923e9
feat(system): extract general info from system service
j10ccc Oct 26, 2024
5d6f384
refactor(notification): gather separate logic
j10ccc Oct 26, 2024
64665ed
refactor(system): new app version hook
j10ccc Oct 26, 2024
1af42f7
feat(binding): new bind checking hook
j10ccc Oct 26, 2024
e0ef186
refactor(home-card): practice bind checking logic
j10ccc Oct 26, 2024
b008376
feat(questionnaire): new offline questionnaire hook
j10ccc Oct 26, 2024
14f6510
refactor(my): practice logic in hook
j10ccc Oct 26, 2024
299c9f0
refactor(home): practice logic in hook
j10ccc Oct 26, 2024
8c59317
chore(store): remove unused store declare
j10ccc Oct 26, 2024
d0bb1e1
refactor(lost-found): practice in new hook
j10ccc Oct 26, 2024
a24508b
refactor(theme): rewrite darkmode and theme in hooks
j10ccc Oct 27, 2024
7633ed9
refactor(nav-bar): rewrite in hooks
j10ccc Oct 27, 2024
98f7fd0
fix(term-picker): remove wrong prop
j10ccc Oct 27, 2024
0484a94
fix(term-picker): get general data from hook
j10ccc Oct 27, 2024
15af27e
refactor(lessons-table): rewrite in hook
j10ccc Oct 27, 2024
0d4438a
refactor(app-list): rewrite in hooks
j10ccc Oct 29, 2024
049201c
feat(request): emit promise params on success in hook
j10ccc Oct 29, 2024
abe31fa
chore(*): remove store import entry and fix broken
j10ccc Oct 29, 2024
1baed74
chore(home): use general info hook
j10ccc Oct 30, 2024
4ba789c
chore(system): remove global loading state
j10ccc Oct 30, 2024
0f725a6
feat(home-card): check if it will have dup before adding
j10ccc Oct 30, 2024
105bef6
refactor(yxy): rewrite apis with new request
j10ccc Oct 30, 2024
8b6f98e
chore(new-feature): remove mute function
j10ccc Oct 30, 2024
9c34748
refactor(bind): rewrite binding tabs in hooks
j10ccc Oct 30, 2024
8040fe1
fix(app-list): cache raw data
j10ccc Oct 31, 2024
4f40bb0
refactor(electricity): rewrite in hooks
j10ccc Nov 1, 2024
3506bf1
chore(service): remove unused logic
j10ccc Nov 1, 2024
0a27749
refactor(library): rewrite in hooks
j10ccc Nov 1, 2024
d8afb13
feat(home): auto get user info
j10ccc Nov 1, 2024
5a5fcc6
refactor(score): rewrite in hooks
j10ccc Nov 1, 2024
af371df
refactor(service): use new request function
j10ccc Nov 1, 2024
83eff9e
Merge pull request #145 from j10ccc/refactor/nice-first-screen
j10ccc Nov 1, 2024
d8cdc10
refactor(free-room): rewrite in hooks
j10ccc Nov 1, 2024
9a0a747
chore(score): move files
j10ccc Nov 1, 2024
fa5ca8f
chore(library): remove unused code
j10ccc Nov 1, 2024
275183b
Merge pull request #146 from j10ccc/refactor/free-room
j10ccc Nov 1, 2024
17c625a
refactor(notification): update notification getter and setter (#147)
j10ccc Nov 2, 2024
40e2e0a
refactor(webview): get target url from encoded url query (#150)
j10ccc Nov 4, 2024
e064b33
refactor(school-card): rewrite in hooks (#151)
j10ccc Nov 11, 2024
64cccbc
refactor(questionnaire): rewrite in hooks (#152)
j10ccc Nov 12, 2024
a17871f
refactor(change-pwd): rewrite in hooks
j10ccc Nov 12, 2024
a5a1dc0
refactor(logout): rewrite in hooks
j10ccc Nov 12, 2024
ea1d06f
perf(settings): remove unused theme logic
j10ccc Nov 12, 2024
cff4122
Merge pull request #154 from j10ccc/refactor/settings
j10ccc Nov 12, 2024
17554ab
chore(image): use taro-image to avoid type error (#155)
j10ccc Nov 12, 2024
52e76de
chore(ci): new type checking step
j10ccc Nov 12, 2024
98afe60
chore(*): remove unused functions
j10ccc Nov 13, 2024
417170a
Merge pull request #156 from j10ccc/chore/type-check
j10ccc Nov 13, 2024
4f2e5e4
fix(electricity): new way to constrain trigger sub (#157)
j10ccc Nov 13, 2024
fea9c97
refactor(exam): rewrite in hooks (#158)
j10ccc Nov 13, 2024
901b70f
feat(title-bar): receive loading state from props (#159)
j10ccc Nov 13, 2024
148945c
feat(button): invoke tap event
j10ccc Nov 14, 2024
b645fc6
refactor(suit): rewrite in hooks
j10ccc Nov 14, 2024
e55ea69
Merge pull request #161 from j10ccc/refactor/suit
j10ccc Nov 14, 2024
4896d57
fix(my): type error on new feature badge
j10ccc Nov 15, 2024
4a67400
fix(lost-found): type error on omit function
j10ccc Nov 15, 2024
771b423
chore(error): remove unused handler
j10ccc Nov 15, 2024
11c6d39
Merge pull request #162 from j10ccc/fix/rest-type-error
j10ccc Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ jobs:
run: |
echo "${{ secrets.ENV_FILE }}" > .env

- name: Lint project
run: pnpm lint
- name: Lint and check type
run: pnpm lint && pnpm typecheck

- name: Build Taro weapp
run: pnpm build:weapp
26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "ZJUTJH",
"scripts": {
"lint": "eslint",
"typecheck": "vue-tsc --noEmit",
"dev:weapp": "npm run build:weapp -- --watch",
"build:weapp": "taro build --type weapp"
},
Expand All @@ -16,37 +17,40 @@
"@babel/runtime": "^7.24.4",
"@tarojs/components": "4.0.6",
"@tarojs/helper": "4.0.6",
"@tarojs/plugin-framework-vue3": "4.0.6",
"@tarojs/plugin-platform-weapp": "4.0.6",
"@tarojs/runtime": "4.0.6",
"@tarojs/shared": "4.0.6",
"@tarojs/taro": "4.0.6",
"@tarojs/plugin-framework-vue3": "4.0.6",
"@vueuse/core": "^11.2.0",
"dayjs": "^1.11.4",
"lodash-es": "^4.17.21",
"vue": "^3.0.0",
"vuex": "^4.0.0",
"vuex-persistedstate": "^4.1.0"
"pinia": "^2.2.4",
"pinia-plugin-persistedstate": "^4.1.1",
"vue": "^3.0.0"
},
"devDependencies": {
"@babel/core": "^7.24.4",
"@babel/plugin-proposal-class-properties": "7.14.5",
"@stylistic/eslint-plugin": "^2.9.0",
"@tarojs/cli": "4.0.6",
"@tarojs/vite-runner": "4.0.6",
"@stylistic/eslint-plugin": "^2.9.0",
"@vue/eslint-config-typescript": "^14.0.0",
"babel-preset-taro": "4.0.6",
"terser": "^5.30.4",
"vite": "^4.2.0",
"@types/lodash-es": "^4.17.12",
"@vitejs/plugin-vue": "^5.0.4",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"@vue/eslint-config-typescript": "^14.0.0",
"babel-preset-taro": "4.0.6",
"eslint": "^9.12.0",
"stylelint": "^14.4.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-vue": "^9.28.0",
"globals": "^15.11.0",
"postcss": "^8.4.38",
"sass": "^1.75.0",
"stylelint": "^14.4.0",
"terser": "^5.30.4",
"typescript": "^5.4.5",
"postcss": "^8.4.38"
"vite": "^4.2.0",
"vue-tsc": "^2.1.10"
}
}
875 changes: 771 additions & 104 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default defineAppConfig({
"pages/connect/faq/index",
"pages/theme/index",
"pages/freeroom/index",
"pages/canteenflow/index",
"pages/announcement/index",
"pages/electricity/index",
"pages/electricity/record/index",
Expand Down
17 changes: 8 additions & 9 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createApp } from "vue";
import store from "./store/index";
import { LoginByTaro, SystemService } from "./services";
import { createPinia } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
import customParseFormat from "dayjs/plugin/customParseFormat";
import relativeTime from "dayjs/plugin/relativeTime";
import dayjs from "dayjs";
Expand All @@ -13,12 +13,11 @@ dayjs.extend(customParseFormat);
dayjs.extend(utc);
dayjs.extend(relativeTime);

const App = createApp({
mounted() {
SystemService.getGeneralInfo();
SystemService.getAppList();
LoginByTaro();
}
}).use(store);
const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);

const App = createApp({});

App.use(pinia);

export default App;
33 changes: 12 additions & 21 deletions src/components/AppList/AppListItem/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@
</template>

<script setup lang="ts">
import { serviceStore } from "@/store";
import Taro from "@tarojs/taro";
import { computed, ref, toRefs } from "vue";
import { computed } from "vue";
import "./index.scss";
import useThemeStore from "@/store/service/theme";

const props = defineProps<{
label: string,
icon: string,
url: string,
bg: string,
require: string,
url: string,
disabled: boolean
}>();
const { require: requireActive, bg = ref("green"), label, url } = toRefs(props);

const themeStore = useThemeStore();

// 主题过渡方案
const icon = props.icon;
const themeMode = computed(() => serviceStore.theme.themeMode);
const iconClass = computed(() => {
if (themeMode.value === "walk") {
if (themeStore.current?.name === "walk") {
if (icon !== "lessonstable" && icon !== "exam" && icon !== "score") {
return "icon-15th-" + icon;
} else {
Expand All @@ -38,30 +39,20 @@ const iconClass = computed(() => {
}
});

const isDisabled = ref(false);
// 之后需要改动,目前zf和oauth的功能是等效的,因此zf和oauth有一个为true即可使用
// 原来的代码是 if (requireActive.value === "zf" && !serviceStore.user.isBindZF)
if (requireActive.value === "zf" && !serviceStore.user.isBindZF && !serviceStore.user.isBindOauth)
isDisabled.value = true;
if (requireActive.value === "library" && !serviceStore.user.isBindLibrary)
isDisabled.value = true;
if (requireActive.value === "yxy" && !serviceStore.user.isBindYXY)
isDisabled.value = true;

async function appTaped() {
if (isDisabled.value) {
if (props.disabled) {
await Taro.navigateTo({ url: "/pages/bind/index" });
Taro.showToast({
icon: "none",
title: "请绑定相关账号"
});
} else if (url.value) await Taro.navigateTo({ url: url.value });
} else await Taro.navigateTo({ url: props.url });
}

const backgroundColor = computed(() => {
if (isDisabled.value)
if (props.disabled)
return { "--bg-color": "var(--wjh-color-light)" };
else return { "--bg-color": `var(--wjh-color-${bg.value}-600)` };
else return { "--bg-color": `var(--wjh-color-${props.bg}-600)` };
});

</script>
15 changes: 6 additions & 9 deletions src/components/AppList/index.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<view v-if="applist" class="applist">
<view v-if="appListStore.list.length" class="applist">
<app-list-item
v-for="(item, index) in applist"
v-for="(item, index) in appListStore.list"
:key="index"
:label="item.title"
:url="item.route"
:icon="item.route.split('/')[2]"
:bg="item.backgroundColor"
:require="item.require"
:disabled="item.disabled"
:icon="item.route.split('/')[2]"
/>
</view>
<card v-else>
Expand All @@ -16,14 +16,11 @@
</template>

<script setup lang="ts">
import { computed } from "vue";
import AppListItem from "./AppListItem/index.vue";
import Card from "../Card/index.vue";
import { serviceStore } from "@/store";
import "./index.scss";
import useAppListStore from "@/store/service/appList";

const applist = computed(() => {
return serviceStore.appList;
});
const appListStore = useAppListStore();

</script>
14 changes: 12 additions & 2 deletions src/components/Button/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<button
<taro-button
:style="{ backgroundColor: `var(--wjh-color-${props.color})` }"
:class="[
`wjh-button`,
Expand All @@ -8,14 +8,16 @@
blockClass,
shapeClass
]"
@tap="handleTap"
>
<slot />
</button>
</taro-button>
</template>

<script setup lang="ts">
import "./index.scss";
import { computed } from "vue";
import { Button as TaroButton } from "@tarojs/components";

type PropsType = {
size?: "small" | "middle" | "large",
Expand All @@ -25,6 +27,10 @@ type PropsType = {
disable?: boolean
};

const emit = defineEmits<{
tap: []
}>();

const props = withDefaults(defineProps<PropsType>(), {
size: "middle",
shape: "default",
Expand All @@ -45,4 +51,8 @@ const shapeClass = computed(() =>
`wjh-button-shape-${props.shape}`
);

function handleTap() {
if (!props.disable) emit("tap");
}

</script>
27 changes: 7 additions & 20 deletions src/components/ElectricityQuickView/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<view v-if="!loading" class="text-wrapper">
<text>寝室剩余电费</text>
<text :class="isUrgent ? 'dangerous' : 'normal'">
{{ balanceData?.data.soc || 0 }}
{{ balance }}
</text>
<text>度</text>
</view>
Expand All @@ -28,36 +28,23 @@ import { QuickView } from "@/components";
import Taro from "@tarojs/taro";
import "./index.scss";
import { computed } from "vue";
import { YxyService } from "@/services";
import store, { serviceStore } from "@/store";
import Card from "../Card/index.vue";
import dayjs from "dayjs";
import { useRequest } from "@/hooks";
import useElectricityBalanceStore from "@/store/service/balance";
import { storeToRefs } from "pinia";

const { loading, balance, error, updateTime } = storeToRefs(useElectricityBalanceStore());

function nav2electricity() {
Taro.navigateTo({ url: "/pages/electricity/index" });
}

const { data: balanceData, loading, error } = useRequest(
YxyService.queryBalance, {
onSuccess: (res) => {
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.soc < 20;
else
return false;
return balance.value < 20;
});

const updateTimeString = computed(() => {
const time = serviceStore.electricity.updateTime.balance;
return time && !error.value ? dayjs(time).fromNow() : "更新失败";
return updateTime.value && !error.value ? dayjs(updateTime.value).fromNow() : "更新失败";
});

</script>
Loading
Loading