Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 18 additions & 1 deletion .eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,23 @@
"DropdownOption": true,
"ConfigProviderProps": true,
"MenuOption": true,
"DataTableRowKey": true
"DataTableRowKey": true,
"useCostAnalysisStore": true,
"useCostBudgetStore": true,
"useCostCollectionStore": true,
"useCostDistributeStore": true,
"useExampleComponentStore": true,
"useHomeFrontStore": true,
"useMaterialBackupStore": true,
"useMaterialPrepareStore": true,
"useMaterialReviewStore": true,
"useMemberAccessStore": true,
"useMemberTeamStore": true,
"useNestedLevelStore": true,
"useProjectStore": true,
"useResultStore": true,
"useUserAccountStore": true,
"useUserAccountStoreWithOut": true,
"StoreActions": true
}
}
50 changes: 50 additions & 0 deletions auto-imports.d.ts

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/modules/HomeFront/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@ export const testData = {
isPublished: false,
createTime: '2021.01.29'
}

/**
* 首页项目列表 模拟数据
*/
export const mockHomeProjectList = Array.from({ length: 50 }).map((item, index) => {
const id = index + 1
return {
id: '' + id,
project_code: 'ACBD' + id,
project_name: '项目' + id,
status: '进行中',
create_time: '2023-06-14 12:00',
create_by: '李华'
}
})
66 changes: 13 additions & 53 deletions src/modules/HomeFront/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ import { Search as IconSearch, Add as IconAdd } from '@vicons/carbon'
import { PaperPlaneRegular as IconPaperPlaneRegular } from '@vicons/fa'
import { NButton } from 'naive-ui'

import type { ProjectItem } from '@/modules/HomeFront/types'


const homeFrontStore = useHomeFrontStore()

/**
* 首页项目列表
Expand All @@ -68,14 +72,6 @@ defineOptions({

const router = useRouter()

type ProjectItem = {
id: string
project_code: string
project_name: string
status: string
create_time: string
create_by: string
}

const tableData = ref<Array<ProjectItem>>([])

Expand Down Expand Up @@ -152,55 +148,19 @@ const handlerPreviewDetail = (row: ProjectItem) => {


const tableLoading = ref(true)
setTimeout(() => {
// tableData.value = [
// {
// id: '1111',
// project_code: 'ACBD',
// project_name: '项目一',
// status: '进行中',
// create_time: '2023-06-14 12:00',
// create_by: '李华'
// },
// {
// id: '222',
// project_code: 'EFGH',
// project_name: '项目二',
// status: '已完成',
// create_time: '2023-06-14 12:00',
// create_by: '李雷'
// }
// ]

tableData.value = Array.from({ length: 50 }).map((item, index) => {

const id = index + 1

return {
id: '' + id,
project_code: 'ACBD' + id,
project_name: '项目' + id,
status: '进行中',
create_time: '2023-06-14 12:00',
create_by: '李华'
}
})

const initHomeProjectList = async () => {
tableLoading.value = true
await homeFrontStore.fetchHomeProjectList()
tableLoading.value = false
}, 300)
}
initHomeProjectList()


const searchValue = ref('')

const filterTableData = ref<Array<ProjectItem>>([])
const handleChangeTableData = _.debounce(
() => {
filterTableData.value = tableData.value.filter(({ project_name }) => {
return searchValue.value.includes(project_name) ||
project_name.includes(searchValue.value)
})
},
400
)
handleChangeTableData()
const filterTableData = computed(() => homeFrontStore.homeProjectList)
const handleChangeTableData = homeFrontStore.fetchSearchHomeProjectList


</script>
Expand Down
37 changes: 36 additions & 1 deletion src/modules/HomeFront/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { defineStore } from 'pinia'

import { sleep } from '@/utils/request'
import * as HomeFrontAPI from '../api'
import * as HomeFrontData from '../data'

import type { ProjectItem } from '@/modules/HomeFront/types'


export const useHomeFrontStore = defineStore('HomeFront', {
state: () => {
return {
demoList: {}
homeProjectList: []
}
},
getters: {
Expand All @@ -16,6 +20,37 @@ export const useHomeFrontStore = defineStore('HomeFront', {
await sleep(200)
const res = await HomeFrontAPI.createProject(query)
return this.filterResponse(res)
},
async fetchHomeProjectList() {
await sleep(320)

const res = {
msg: 'ok',
error: 0,
data: HomeFrontData.mockHomeProjectList
}

return this.filterResponse(res, ({ data }) => {
this.homeProjectList = data
})
},
fetchSearchHomeProjectList(searchValue = '') {
const res = {
msg: 'ok',
error: 0,
data: HomeFrontData.mockHomeProjectList
}

return this.filterResponse(res, ({ data }) => {
this.homeProjectList = data.filter(projectItem => {
const { project_name } = projectItem as ProjectItem
return searchValue.includes(project_name) ||
project_name.includes(searchValue)
})
})
}
},
debounce: {
fetchSearchHomeProjectList: 400
}
})
8 changes: 8 additions & 0 deletions src/modules/HomeFront/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type ProjectItem = {
id: string
project_code: string
project_name: string
status: string
create_time: string
create_by: string
}
9 changes: 7 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { createPinia } from 'pinia'
import { pluginPinia } from '@/store/plugins'
import {
pluginExternalProperties,
pluginDebounceAction
} from '@/store/plugins'

const store = createPinia()

export function setupStore(app: App<Element>) {
app.use(store)
}

store.use(pluginPinia)
store.use(pluginExternalProperties)
store.use(pluginDebounceAction)

export { store }
13 changes: 13 additions & 0 deletions src/store/plugins/debounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 支持使用任意防抖库
export const pluginDebounceAction = ({ options, store }) => {
if (options.debounce) {
// 使用新的 action 来覆盖这些 action
return Object.keys(options.debounce).reduce((debouncedActions, action) => {
debouncedActions[action] = _.debounce(
store[action],
options.debounce![action]
)
return debouncedActions
}, {})
}
}
7 changes: 7 additions & 0 deletions src/store/plugins/externalProperties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getFilterResponse } from '@/store/utils/mixin'
import router from '@/router'

export const pluginExternalProperties = ({ store }) => {
store.filterResponse = getFilterResponse
store.router = router
}
9 changes: 2 additions & 7 deletions src/store/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@
* Plugins for Pinia
*/

import { getFilterResponse } from '@/store/utils/mixin'
import router from '@/router'

export const pluginPinia = ({ store }) => {
store.filterResponse = getFilterResponse
store.router = router
}
export { pluginExternalProperties } from '@/store/plugins/externalProperties'
export { pluginDebounceAction } from '@/store/plugins/debounce'
2 changes: 1 addition & 1 deletion src/store/utils/mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getFilterResponse(
} else {
errorCallback
? errorCallback(res)
: window.$message.error(res.msg!, {
: window.$ModalMessage.error(res.msg!, {
closable: true
})
}
Expand Down
4 changes: 4 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ declare module 'pinia' {
filterResponse: typeof getFilterResponse
router: typeof router
}
export interface DefineStoreOptionsBase<S, Store> {
// 任意 action 都允许定义一个防抖的毫秒数
debounce?: Partial<Record<keyof StoreActions<Store>, number>>
}
}

declare module 'vue-router' {
Expand Down
10 changes: 9 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,22 @@ export default defineConfig(({ mode }) => {
'FormInst'
],
type: true
},
{
from: 'pinia',
imports: [
'StoreActions'
],
type: true
}
],
resolvers:
mode === 'development'
? []
: [NaiveUiResolver()],
dirs: [
'./src/hooks'
'./src/hooks',
'./src/modules/**/store'
],
dts: './auto-imports.d.ts',
eslintrc: {
Expand Down