Skip to content

Commit b833160

Browse files
author
白唯
committed
feat(测试): 添加测试例子,完善vuex的类型
1 parent 5c94b91 commit b833160

File tree

9 files changed

+103
-147
lines changed

9 files changed

+103
-147
lines changed

@types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export declare interface StoreInstance extends ReturnType<typeof createStore> {
1111
type ModuleType = { app: AppStateType }
1212

1313
// 所有的SateType
14-
export type StateType = { state: ModuleType & RootStateType & StoreInstance }
14+
export type StateType = ModuleType & RootStateType & StoreInstance
1515

1616
// request interceptors
1717
export declare interface ApiResponse {

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- webpack 插件:style-resources-loader
1414

1515
#### 代码基础架构说明
16+
1617
```
1718
|-- 根目录
1819
|-- @types 项目共用的 type
@@ -76,6 +77,7 @@
7677
|-- typedoc.json 文档配置文件
7778
|-- vue.config.js <font color="red">vue-cli 脚手架配置文件</font>
7879
```
80+
7981
#### 组件编写
8082

8183
- [x] 支持 tsx 方式编写页面,在.tsx 文件或者 class-component 里写 tsx.

directoryList.md

-130
This file was deleted.

global.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { StateType } from '@types'
22
import { Message } from 'ant-design-vue/types/message'
33
import { Router, RouteLocationNormalizedLoaded } from 'vue-router'
4+
import { Store } from 'vuex'
45

56
/** 将第三方变量挂载到每一个 vue 示例中 */
67
declare module '@vue/runtime-core' {
78
interface ComponentCustomProperties {
89
$message: Message
9-
$store: StateType
10+
$store: Store<StateType>
1011
$route: RouteLocationNormalizedLoaded
1112
$router: Router
1213
}

src/App.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div id="app">
3-
<full-loading :show="fullLoading" text="hehhe" />
3+
<full-loading :show="fullLoading" :text="loadingText" />
44
<div id="nav">
55
<router-link to="/">Home</router-link> | <router-link to="/about">About</router-link> | <router-link to="/contact">Contact</router-link> |
66
<router-link to="/tests">组件测试</router-link>
@@ -19,12 +19,12 @@ const App = defineComponent({
1919
hello: 'iis'
2020
}
2121
},
22-
created() {
23-
console.log(this.$store)
24-
},
2522
computed: {
2623
fullLoading() {
2724
return this.$store.state.fullLoading
25+
},
26+
loadingText() {
27+
return this.$store.state.loadingText
2828
}
2929
}
3030
})

src/plugins/antd.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Button, Card, Row, Col } from 'ant-design-vue'
1+
import { Button, Card, Row, Col, Tag, Form, Input } from 'ant-design-vue'
22
import { createApp } from 'vue'
33

44
/**
55
* @description 手动注册 antd-vue 组件,达到按需加载目的
6+
* @description Automatically register components under Button, such as Button.Group
67
* @param {ReturnType<typeof createApp>} app 整个应用的实例
78
* @returns void
89
*/
@@ -11,6 +12,7 @@ export function loadAtdComponent(app: ReturnType<typeof createApp>) {
1112
app.use(Card)
1213
app.use(Row)
1314
app.use(Col)
15+
app.use(Tag)
16+
app.use(Form)
17+
app.use(Input)
1418
}
15-
16-
/* Automatically register components under Button, such as Button.Group */

src/store/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const store: StoreInstance = createStore({
1010
state: state,
1111
mutations,
1212
actions: {},
13-
...modules,
13+
modules: { ...modules },
1414
plugins: [
1515
createPersistedState({
1616
paths: ['app']

src/store/state.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
const state: RootStateType = {
2-
fullLoading: false
1+
const state = {
2+
fullLoading: false,
3+
loadingText: 'Loading...'
34
}
45

5-
type RootStateType = {
6-
fullLoading: boolean
7-
}
6+
type RootStateType = typeof state
87

98
export { state, RootStateType }

src/views/test/Test.vue

+84-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,55 @@
11
<template>
22
<div>
33
<a-card class="card">
4+
<full-loading :show="loading" :text="loadingText" />
45
<p>全局组件测试</p>
56
<a-row>
6-
<a-col :span="12"> <a-button @click="openFullLoading">全局加载 3 秒</a-button> </a-col>
7-
<a-col :span="12"> <a-button @click="openFullLoading">局部加载 </a-button> </a-col>
7+
<a-col :span="12"> <a-button type="primary" @click="openFullLoading">全局加载 3 秒</a-button> </a-col>
8+
<a-col :span="12"> <a-button @click="openPartLoading">局部加载 </a-button> </a-col>
89
</a-row>
910
</a-card>
1011

1112
<a-card class="card">
1213
<p>vuex测试</p>
14+
<a-row>
15+
<a-col :span="12">
16+
<p>app模块</p>
17+
<p>
18+
<a-tag v-for="(item, key, index) of app" :key="index" color="pink">{{ `${key}:${item}` }}</a-tag>
19+
</p>
20+
21+
<a-form :label-col="labelCol" :wrapper-col="wrapperCol">
22+
<a-form-item label="更改主题名">
23+
<a-row>
24+
<a-col :span="18">
25+
<a-input v-model:value="inputValue" />
26+
</a-col>
27+
<a-col :span="6">
28+
<a-button type="success" @click="changeTheme">确认</a-button>
29+
</a-col>
30+
</a-row>
31+
</a-form-item>
32+
</a-form>
33+
</a-col>
34+
<a-col :span="12">
35+
<p>根模块</p>
36+
<p>
37+
<a-tag color="pink">{{ `loadingText:${loadingText}` }}</a-tag>
38+
</p>
39+
<a-form :label-col="{ span: 6 }" :wrapper-col="wrapperCol">
40+
<a-form-item label="全局加载文字">
41+
<a-row>
42+
<a-col :span="16">
43+
<a-input v-model:value="globalLoadingText" />
44+
</a-col>
45+
<a-col offset="2" :span="6">
46+
<a-button type="success" @click="changeText">更改并打开</a-button>
47+
</a-col>
48+
</a-row>
49+
</a-form-item>
50+
</a-form>
51+
</a-col>
52+
</a-row>
1353
</a-card>
1454
</div>
1555
</template>
@@ -18,8 +58,49 @@
1858
import { defineComponent } from 'vue'
1959
2060
export default defineComponent({
61+
data() {
62+
return {
63+
labelCol: { span: 4 },
64+
wrapperCol: { span: 14 },
65+
loading: false,
66+
inputValue: '',
67+
globalLoadingText: ''
68+
}
69+
},
70+
created() {
71+
console.log(this.app)
72+
},
73+
computed: {
74+
app() {
75+
return this.$store.state.app
76+
},
77+
loadingText() {
78+
return this.$store.state.loadingText
79+
}
80+
},
2181
methods: {
82+
/**
83+
* @description 更改 vuex 主题名
84+
*/
85+
changeTheme() {
86+
console.log(this.inputValue)
87+
this.$store.__s('app.theme', this.inputValue)
88+
},
89+
changeText() {
90+
this.$store.__s('loadingText', this.globalLoadingText)
91+
this.$store.__s('fullLoading', true)
92+
setTimeout(() => {
93+
this.$store.__s('fullLoading', false)
94+
}, 3000)
95+
},
96+
openPartLoading() {
97+
this.loading = true
98+
setTimeout(() => {
99+
this.loading = false
100+
}, 3000)
101+
},
22102
openFullLoading() {
103+
this.$store.__s('loadingText', '全局加载中')
23104
this.$store.__s('fullLoading', true)
24105
setTimeout(() => {
25106
this.$store.__s('fullLoading', false)
@@ -32,5 +113,6 @@ export default defineComponent({
32113
<style lang="less" scoped>
33114
.card {
34115
margin-top: 30px;
116+
position: relative;
35117
}
36118
</style>

0 commit comments

Comments
 (0)