1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-05 15:01:23 +08:00

add pinia to manage data

This commit is contained in:
cccccyb
2023-05-12 02:39:56 +08:00
parent aed3c40196
commit 7e75600154
8 changed files with 205 additions and 118 deletions

View File

@@ -1,51 +1,105 @@
<template> <template>
<div class="notice-head-layout"> <el-form
<el-row> :inline="true"
<el-col :span="2" :xs="3" :sm="2" :model="search_info"
><el-text class="demo-form-inline"
class="mx-1" label-width="auto"
size="large" ref="searchForm"
style="color: rgba(71, 138, 173, 0.85); font-weight: bolder" style="min-width: 1185px"
>公告标题</el-text >
></el-col <el-row :span="24">
>
<el-col :span="4">
<el-input v-model="search_info.title" placeholder="请输入公告标题"> </el-input>
</el-col>
<el-col :span="1"></el-col>
<el-col :span="2" :xs="3" :sm="2"
><el-text
class="mx-1"
size="large"
style="color: rgba(71, 138, 173, 0.85); font-weight: bolder"
>公告类型</el-text
></el-col
>
<el-col :span="4">
<el-input v-model="search_info.type" placeholder="请输入公告类型"> </el-input>
</el-col>
<el-col :span="1"></el-col>
<el-col :span="5"> <el-col :span="5">
<el-date-picker <el-form-item label="公告标题:" prop="title">
v-model="timeRang" <el-input v-model="search_info.title" placeholder="请输入公告标题"></el-input>
type="datetimerange" </el-form-item>
range-separator=""
start-placeholder="开始日期"
end-placeholder="结束日期"
>
</el-date-picker>
</el-col> </el-col>
<el-col :span="2"></el-col> <el-col :span="5">
<el-col :span="3"> <el-form-item label="公告类型:" prop="type">
<el-button type="primary" @click="selectByCondition"> <el-select v-model="search_info.type" placeholder="请选择公告类型">
<el-icon :size="SIZE_ICON_SM()" style="color: white; margin-right: 5px"> <el-option
<icon-pinnacle-notice_search /> v-for="item in noticeTypeList"
</el-icon> :key="item.id"
搜索 :label="item.name"
</el-button> :value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="日期:" prop="timeRang">
<el-date-picker
v-model="timeRang"
type="datetimerange"
range-separator=""
start-placeholder="开始日期"
end-placeholder="结束日期"
style="width: auto"
>
</el-date-picker>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item>
<el-button type="primary" @click="selectByCondition"
><el-icon :size="SIZE_ICON_SM()" style="color: white; margin-right: 5px">
<icon-pinnacle-notice_search /> </el-icon
>查询</el-button
>
<el-button type="primary" @click="resetForm"
><el-icon :size="SIZE_ICON_SM()" style="color: white">
<icon-pinnacle-reset /> </el-icon
>重置</el-button
>
</el-form-item>
</el-col> </el-col>
</el-row> </el-row>
</div> </el-form>
<!-- <el-row>-->
<!-- <el-col :span="2" :xs="3" :sm="2"-->
<!-- ><el-text-->
<!-- class="mx-1"-->
<!-- size="large"-->
<!-- style="color: rgba(71, 138, 173, 0.85); font-weight: bolder"-->
<!-- >公告标题</el-text-->
<!-- ></el-col-->
<!-- >-->
<!-- <el-col :span="4">-->
<!-- <el-input v-model="search_info.title" placeholder="请输入公告标题"> </el-input>-->
<!-- </el-col>-->
<!-- <el-col :span="1"></el-col>-->
<!-- <el-col :span="2" :xs="3" :sm="2"-->
<!-- ><el-text-->
<!-- class="mx-1"-->
<!-- size="large"-->
<!-- style="color: rgba(71, 138, 173, 0.85); font-weight: bolder"-->
<!-- >公告类型</el-text-->
<!-- ></el-col-->
<!-- >-->
<!-- <el-col :span="4">-->
<!-- <el-input v-model="search_info.type" placeholder="请输入公告类型"> </el-input>-->
<!-- </el-col>-->
<!-- <el-col :span="1"></el-col>-->
<!-- <el-col :span="5">-->
<!-- <el-date-picker-->
<!-- v-model="timeRang"-->
<!-- type="datetimerange"-->
<!-- range-separator="至"-->
<!-- start-placeholder="开始日期"-->
<!-- end-placeholder="结束日期"-->
<!-- >-->
<!-- </el-date-picker>-->
<!-- </el-col>-->
<!-- <el-col :span="2"></el-col>-->
<!-- <el-col :span="3">-->
<!-- <el-button type="primary" @click="selectByCondition">-->
<!-- <el-icon :size="SIZE_ICON_SM()" style="color: white; margin-right: 5px">-->
<!-- <icon-pinnacle-notice_search />-->
<!-- </el-icon>-->
<!-- 搜索-->
<!-- </el-button>-->
<!-- </el-col>-->
<!-- </el-row>-->
</template> </template>
<script lang="ts"> <script lang="ts">
@@ -54,6 +108,18 @@ import _ from 'lodash'
export default { export default {
name: 'NoticeHead', name: 'NoticeHead',
data() {
return {
noticeTypeList: [],
timeRang: [],
search_info: {
title: '',
type: '',
startTime: '',
endTime: ''
}
}
},
methods: { methods: {
SIZE_ICON_SM() { SIZE_ICON_SM() {
return SIZE_ICON_SM return SIZE_ICON_SM
@@ -82,38 +148,17 @@ export default {
const ss = _.padStart(dateParse.getUTCSeconds().toString(), 2, '0') const ss = _.padStart(dateParse.getUTCSeconds().toString(), 2, '0')
newFormat = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss newFormat = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
return newFormat return newFormat
} },
}, resetForm() {
data() { this.timeRang = []
return { this.$refs.searchForm.resetFields()
timeRang: [],
search_info: {
title: '',
type: '',
startTime: '',
endTime: ''
}
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
.el-row { .el-form {
height: 80%;
margin-top: 15px; margin-top: 15px;
} }
.el-row:last-child {
margin-bottom: 0;
}
.el-col {
border-radius: 4px;
}
.grid-content {
border-radius: 4px;
min-height: 36px;
}
</style> </style>

View File

@@ -113,6 +113,9 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { useNoticeManageStore } from '@/store/notice-manage'
const noticeManageStore = useNoticeManageStore()
export default { export default {
data() { data() {
return { return {
@@ -121,10 +124,12 @@ export default {
dialogShowVisible: false, dialogShowVisible: false,
noticeEdit: {}, noticeEdit: {},
noticeShow: {}, noticeShow: {},
getLoading: true getLoading: true,
selectData: [],
loading: true
} }
}, },
props: ['noticeTypeList', 'selectData', 'departmentList', 'dialogUpdateVisible', 'loading'], props: ['noticeTypeList', 'departmentList', 'dialogUpdateVisible'],
methods: { methods: {
clearFilter() { clearFilter() {
this.$refs.tableRef.clearFilter(['senderName']) this.$refs.tableRef.clearFilter(['senderName'])
@@ -161,7 +166,11 @@ export default {
this.dialogShowVisible = visible this.dialogShowVisible = visible
} }
}, },
mounted() {}, mounted() {
noticeManageStore.selectAllNotice()
this.selectData = noticeManageStore.selectData
this.loading = noticeManageStore.loading
},
updated() { updated() {
this.$refs.tableRef.clearFilter(['senderName']) this.$refs.tableRef.clearFilter(['senderName'])
this.filterSenderName = [] this.filterSenderName = []
@@ -178,7 +187,6 @@ export default {
senderName.value = newArr[j] senderName.value = newArr[j]
this.filterSenderName.push(senderName) this.filterSenderName.push(senderName)
} }
// console.log(this.filterSenderName)
} }
} }
</script> </script>

View File

@@ -6,10 +6,10 @@
>清除筛选条件 >清除筛选条件
</el-button> </el-button>
<el-table <el-table
v-loading="getLoading" v-loading="loading"
element-loading-text="加载中..." element-loading-text="加载中..."
ref="tableRef" ref="tableRef"
:data="selectData" :data="tableData"
style="width: 100%" style="width: 100%"
border border
highlight-current-row highlight-current-row
@@ -102,15 +102,22 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { useNoticeViewStore } from '@/store/notice-view'
// import { mapState } from 'pinia'
// import { storeToRefs } from 'pinia'
const noticeViewStore = useNoticeViewStore()
// const { selectData, getLoading } = storeToRefs(noticeViewStore)
export default { export default {
data() { data() {
return { return {
filterSenderName: [], filterSenderName: [],
dialogShowVisible: false, dialogShowVisible: false,
noticeShow: {} noticeShow: {},
tableData: [],
loading: true
} }
}, },
props: ['selectData', 'getLoading'], props: [],
methods: { methods: {
clearFilter() { clearFilter() {
this.$refs.tableRef.clearFilter(['senderName']) this.$refs.tableRef.clearFilter(['senderName'])
@@ -137,13 +144,17 @@ export default {
this.dialogShowVisible = visible this.dialogShowVisible = visible
} }
}, },
mounted() {}, mounted() {
noticeViewStore.selectAllNoticeByUserId()
this.loading = noticeViewStore.getLoading
this.tableData = noticeViewStore.selectData
},
updated() { updated() {
this.$refs.tableRef.clearFilter(['senderName']) this.$refs.tableRef.clearFilter(['senderName'])
this.filterSenderName = [] this.filterSenderName = []
const nameArray = [] const nameArray = []
for (let i = 0; i < this.selectData.length; i++) { for (let i = 0; i < noticeViewStore.selectData.length; i++) {
nameArray.push(this.selectData[i].sender.username) nameArray.push(noticeViewStore.selectData[i].sender.username)
} }
const newArr = nameArray.filter((item, i, arr) => { const newArr = nameArray.filter((item, i, arr) => {
return arr.indexOf(item) === i return arr.indexOf(item) === i

View File

@@ -22,11 +22,9 @@
></commitForm> ></commitForm>
</el-dialog> </el-dialog>
<notice-manage-table <notice-manage-table
:selectData="selectData"
:noticeTypeList="noticeTypeList" :noticeTypeList="noticeTypeList"
:departmentList="departmentList" :departmentList="departmentList"
:dialogUpdateVisible="dialogUpdateVisible" :dialogUpdateVisible="dialogUpdateVisible"
:loading="loading"
@handleDelete="handleDelete" @handleDelete="handleDelete"
@clearFilter="clearFilter" @clearFilter="clearFilter"
@handleUpdateNotice="handleUpdateNotice" @handleUpdateNotice="handleUpdateNotice"
@@ -45,12 +43,10 @@ export default {
name: 'NoticeHome', name: 'NoticeHome',
data() { data() {
return { return {
selectData: [],
noticeTypeList: [], noticeTypeList: [],
dialogAddVisible: false, dialogAddVisible: false,
dialogUpdateVisible: false, dialogUpdateVisible: false,
departmentList: [], departmentList: []
loading: true
} }
}, },
methods: { methods: {
@@ -64,7 +60,7 @@ export default {
}) })
.then((response) => { .then((response) => {
if (response.data.code === 20021) { if (response.data.code === 20021) {
this.selectData = response.data.data // this.selectData = response.data.data
ElMessage({ ElMessage({
message: '查询成功.', message: '查询成功.',
type: 'success' type: 'success'
@@ -77,14 +73,6 @@ export default {
} }
}) })
}, },
selectAllNotice() {
request.get('http://localhost:8621/notice').then((response) => {
this.selectData = response.data.data
if (this.selectData) {
this.loading = false
}
})
},
handleDelete(deleteID) { handleDelete(deleteID) {
ElMessageBox.confirm('确定是否要删除?该操作将无法回退', '警告', { ElMessageBox.confirm('确定是否要删除?该操作将无法回退', '警告', {
confirmButtonText: '确定', confirmButtonText: '确定',
@@ -165,9 +153,7 @@ export default {
this.$router.go(0) this.$router.go(0)
} }
}, },
mounted() { mounted() {}
this.selectAllNotice()
}
} }
</script> </script>

View File

@@ -14,43 +14,36 @@
<el-menu-item index="2">已读</el-menu-item> <el-menu-item index="2">已读</el-menu-item>
<el-menu-item index="3"><a href="#">未读</a></el-menu-item> <el-menu-item index="3"><a href="#">未读</a></el-menu-item>
</el-menu> </el-menu>
<notice-view-table <notice-view-table></notice-view-table>
:selectData="selectData"
:getLoading="getLoading"
></notice-view-table>
</el-main> </el-main>
</el-container> </el-container>
</template> </template>
<script lang="ts"> <script lang="ts">
import request from '@/services' import { useNoticeViewStore } from '@/store/notice-view'
const noticeViewStore = useNoticeViewStore()
export default { export default {
name: 'NoticeView', name: 'NoticeView',
data() { data() {
return { return {
activeIndex: '1', activeIndex: '1'
selectData: [],
getLoading: true
} }
}, },
methods: { methods: {
handleSelect(key, keyPath) { handleSelect(key, keyPath) {
console.log(key, keyPath) console.log(key, keyPath)
},
selectAllNoticeByUserId() {
request.get('http://localhost:8621/notice/ByUserId').then((response) => {
this.selectData = response.data.data
if (this.selectData) {
this.getLoading = false
}
})
} }
}, },
mounted() { mounted() {}
this.selectAllNoticeByUserId()
}
} }
</script> </script>
<style scoped></style> <style scoped>
.el-header {
background-color: #fff;
}
.el-main {
padding: 0;
margin-top: 20px;
}
</style>

View File

@@ -0,0 +1,22 @@
import { defineStore } from 'pinia'
import request from '@/services'
export const useNoticeManageStore = defineStore('notice-manage', {
state: () => {
return {
selectData: [],
loading: true
}
},
getters: {},
actions: {
selectAllNotice() {
void request.get('http://localhost:8621/notice').then((response) => {
this.selectData = response.data.data
if (this.selectData.length !== 0) {
this.loading = false
}
})
}
}
})

View File

@@ -0,0 +1,22 @@
import { defineStore } from 'pinia'
import request from '@/services'
export const useNoticeViewStore = defineStore('notice-view', {
state: () => {
return {
selectData: [],
getLoading: true
}
},
getters: {},
actions: {
selectAllNoticeByUserId(): void {
void request.get('http://localhost:8621/notice/ByUserId').then((response) => {
this.selectData = response.data.data
if (this.selectData.length !== 0) {
this.getLoading = false
}
})
}
}
})

View File