Skip to content

Commit da21e87

Browse files
authored
fix(log): three relevant components (#422)
1 parent bdaa431 commit da21e87

9 files changed

Lines changed: 89 additions & 87 deletions

File tree

.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
ENV = 'development'
22

3-
VUE_APP_BASE_URL = 'http://face.api.talelin.com/'
3+
VUE_APP_BASE_URL = 'http://119.45.196.33:5000/'

babel.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable comma-dangle */
21
module.exports = {
32
presets: [['@vue/cli-plugin-babel/preset']],
43
plugins: [

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@tinymce/tinymce-vue": "^2.0.0",
1919
"axios": "~0.18.0",
2020
"core-js": "^3.6.5",
21+
"dayjs": "^1.10.4",
2122
"element-plus": "^1.0.1-beta.19",
2223
"event-source-polyfill": "^1.0.7",
2324
"fastscan": "^1.0.4",

src/component/base/date-picker/lin-date-picker.vue

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,55 @@
99
align="right"
1010
size="medium"
1111
popper-class="date-box"
12-
value-format="yyyy-MM-dd HH:mm:ss"
13-
:default-time="['00:00:00', '23:59:59']"
14-
:picker-options="pickerOptions"
12+
:default-time="defaultTime"
13+
:shortcuts="shortcuts"
1514
>
1615
</el-date-picker>
1716
</div>
1817
</template>
1918

2019
<script type="text/ecmascript-6">
20+
import dayjs from 'dayjs'
21+
2122
export default {
2223
data() {
2324
return {
2425
value: '',
25-
pickerOptions: {
26-
shortcuts: [{
27-
text: '最近一周',
28-
onClick(picker) {
29-
const end = new Date()
30-
const start = new Date()
31-
start.setTime(start.getTime() - (3600 * 1000 * 24 * 7))
32-
picker.$emit('pick', [start, end])
33-
},
34-
}, {
35-
text: '最近一个月',
36-
onClick(picker) {
37-
const end = new Date()
38-
const start = new Date()
39-
start.setTime(start.getTime() - (3600 * 1000 * 24 * 30))
40-
picker.$emit('pick', [start, end])
41-
},
42-
}, {
43-
text: '最近三个月',
44-
onClick(picker) {
45-
const end = new Date()
46-
const start = new Date()
47-
start.setTime(start.getTime() - (3600 * 1000 * 24 * 90))
48-
picker.$emit('pick', [start, end])
49-
},
50-
}],
51-
},
26+
defaultTime: [
27+
new Date(2000, 1, 1, 0, 0, 0),
28+
new Date(2000, 2, 1, 23, 59, 59)
29+
],
30+
shortcuts: [{
31+
text: '最近一周',
32+
value: (() => {
33+
const end = new Date()
34+
const start = new Date()
35+
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
36+
return [start, end]
37+
})(),
38+
}, {
39+
text: '最近一个月',
40+
value: (() => {
41+
const end = new Date()
42+
const start = new Date()
43+
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
44+
return [start, end]
45+
})(),
46+
}, {
47+
text: '最近三个月',
48+
value: (() => {
49+
const end = new Date()
50+
const start = new Date()
51+
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
52+
return [start, end]
53+
})(),
54+
}]
55+
5256
}
5357
},
5458
watch: {
5559
value(date) {
56-
this.$emit('dateChange', date)
60+
this.$emit('dateChange', date ? date.map(item => dayjs(item).format('YYYY-MM-DD HH:mm:ss')) : '')
5761
},
5862
},
5963
methods: {

src/component/base/search/lin-search.vue

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<template>
22
<div class="lin-search">
33
<el-input size="medium" :placeholder="placeholder" clearable v-model="keyword" class="input-with-select">
4-
<el-button icon="el-icon-search"></el-button>
4+
<template #suffix>
5+
<i class="el-input__icon el-icon-search" @click="search"></i>
6+
</template>
57
</el-input>
68
</div>
79
</template>
@@ -34,30 +36,24 @@ export default {
3436
clear() {
3537
this.keyword = ''
3638
},
39+
search() {
40+
this.$emit('query', this.keyword)
41+
},
3742
},
3843
}
3944
</script>
4045
<style lang="scss" scoped>
41-
.lin-search >>> .el-input-group__append {
42-
border-top-right-radius: 20px;
43-
border-bottom-right-radius: 20px;
44-
padding: 0 8px;
45-
color: #ffffff;
46-
border: 1px solid $theme;
47-
.el-icon-search {
48-
font-size: 18px;
49-
}
50-
}
51-
.lin-search >>> .el-input__inner {
52-
border-top-left-radius: 20px;
53-
border-bottom-left-radius: 20px;
54-
border-right: none;
46+
.lin-search /deep/ .el-input__inner {
5547
width: 150px;
48+
border-radius: 20px;
5649
transition: all 0.2s linear;
5750
5851
&:focus {
5952
width: 250px;
6053
transition: all 0.3s linear;
6154
}
6255
}
56+
.lin-search /deep/ .el-input__suffix {
57+
cursor: pointer;
58+
}
6359
</style>

src/lin/model/log.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable class-methods-use-this */
21
import _axios, { get } from '@/lin/plugin/axios'
32

43
class Log {

src/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import 'dayjs/locale/zh-cn'
12
import { createApp } from 'vue'
23
import ElementPlus from 'element-plus'
4+
import locale from 'element-plus/lib/locale/lang/zh-cn'
35

46
import '@/config/global'
57
import 'lin/plugin'
@@ -22,7 +24,7 @@ const app = createApp(App)
2224

2325
app.use(store)
2426
app.use(router)
25-
app.use(ElementPlus)
27+
app.use(ElementPlus, { locale })
2628

2729
// base 组件注册
2830
app.component('l-icon', LIcon)
@@ -35,7 +37,5 @@ app.directive('permission', permissionDirective)
3537

3638
app.mount('#app')
3739

38-
app.config.devtools = true
39-
4040
// 设置 App 实例
4141
window.App = app

src/view/log/log.vue

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
<!--
2-
TODO: Vue3 mapGetters 简化用法
3-
-->
41
<template>
52
<div class="log">
63
<sticky-top>
74
<div class="log-header">
85
<div class="header-left"><p class="title">日志信息</p></div>
96
<div class="header-right" v-permission="'搜索日志'">
10-
<lin-search @query="onQueryChange" ref="searchKeywordDOM" />
7+
<lin-search @query="onQueryChange" ref="searchKeywordDom" />
118
<el-dropdown
129
size="medium"
1310
style="margin: 0 10px;"
1411
@command="handleCommand"
1512
v-permission="'查询日志记录的用户'"
1613
>
17-
<el-button size="medium">
14+
<el-button>
1815
{{ searchUser ? searchUser : '全部人员' }} <i class="el-icon-arrow-down el-icon--right"></i>
1916
</el-button>
20-
<el-dropdown-menu>
21-
<template v-slot:dropdown>
17+
<template #dropdown>
18+
<el-dropdown-menu>
2219
<el-dropdown-item :command="['全部人员']">全部人员</el-dropdown-item>
2320
<el-dropdown-item
2421
icon="el-icon-user-solid"
@@ -27,10 +24,10 @@
2724
:command="[user]"
2825
>{{ user }}
2926
</el-dropdown-item>
30-
</template>
31-
</el-dropdown-menu>
27+
</el-dropdown-menu>
28+
</template>
3229
</el-dropdown>
33-
<lin-date-picker @dateChange="handleDateChange" ref="searchDateDOM" class="date"> </lin-date-picker>
30+
<lin-date-picker @dateChange="handleDateChange" ref="searchDateDom" class="date"> </lin-date-picker>
3431
</div>
3532
</div>
3633
<el-divider v-if="!keyword"></el-divider>
@@ -57,19 +54,21 @@
5754
</section>
5855
</article>
5956

60-
<div v-if="logs?.length">
61-
<el-divider></el-divider>
62-
<div class="more" :class="{ nothing: finished }">
63-
<i v-if="more" class="iconfont icon-loading"></i>
64-
<div v-show="!more && !finished" @click="nextPage">
65-
<span>查看更多</span> <i class="iconfont icon-gengduo" style="font-size:14px"></i>
66-
</div>
67-
<div v-if="finished">
68-
<span>{{ totalCount === 0 ? '暂无数据' : '没有更多数据了' }}</span>
57+
<div v-if="totalCount > count">
58+
<div v-if="logs?.length">
59+
<el-divider></el-divider>
60+
<div class="more" :class="{ nothing: finished }">
61+
<i v-if="more" class="iconfont icon-loading"></i>
62+
<div v-show="!more && !finished" @click="nextPage">
63+
<span>查看更多</span> <i class="iconfont icon-gengduo" style="font-size:14px"></i>
64+
</div>
65+
<div v-if="finished">
66+
<span>{{ totalCount === 0 ? '暂无数据' : '没有更多数据了' }}</span>
67+
</div>
6968
</div>
7069
</div>
70+
<div class="nothing" v-else>暂无日志信息</div>
7171
</div>
72-
<div class="nothing" v-else>暂无日志信息</div>
7372
</div>
7473
</div>
7574
</template>
@@ -88,17 +87,20 @@ export default {
8887
LinSearch,
8988
LinDatePicker,
9089
},
91-
setup(props, ctx) {
90+
setup() {
9291
// originally data properties
9392
const store = useStore()
94-
const permissions = computed(() => store.getters.permissions)
9593
const user = computed(() => store.getters.user)
94+
const permissions = computed(() => store.getters.permissions)
9695
97-
const loading = ref(false)
98-
const users = ref([])
96+
const count = 10
9997
const logs = ref([])
98+
const users = ref([])
99+
const loading = ref(false)
100100
const isSearch = ref(false)
101101
const finished = ref(false)
102+
const searchDateDom = ref()
103+
const searchKeywordDom = ref()
102104
103105
/**
104106
* Part 1
@@ -110,7 +112,7 @@ export default {
110112
if (user.value.admin || permissions.value.includes('查询日志记录的用户')) {
111113
users.value = await logModel.getLoggedUsers({})
112114
}
113-
const res = await logModel.getLogs({ page: 0 })
115+
const res = await logModel.getLogs({ page: 0, count })
114116
logs.value = res.items
115117
loading.value = false
116118
} catch (err) {
@@ -145,14 +147,12 @@ export default {
145147
}
146148
// 条件检索
147149
const searchPage = async () => {
148-
if (!search.searchUser && !search.searchKeyword && !search.searchDate.length) {
149-
return
150-
}
151-
search.totalCount = 0
152150
logs.value = []
153151
loading.value = true
152+
search.totalCount = 0
154153
finished.value = false
155154
const name = search.searchUser === '全部人员' ? '' : search.searchUser
155+
156156
const res = await logModel.searchLogs({
157157
page: 0, // 初始化
158158
keyword: search.searchKeyword,
@@ -194,7 +194,7 @@ export default {
194194
if (search.searchDate.length) {
195195
search.keyword = `${search.searchUser} ${search.searchDate[0]}${search.searchDate[1]}`
196196
}
197-
ctx.refs.searchKeywordDOM.clear()
197+
searchKeywordDom.value.clear()
198198
}
199199
searchPage()
200200
},
@@ -237,7 +237,7 @@ export default {
237237
if (search.searchKeyword) {
238238
search.keyword = `${search.searchUser} ${search.searchKeyword}`
239239
}
240-
ctx.refs.searchDateDOM.clear()
240+
searchDateDom.value.clear()
241241
}
242242
searchPage()
243243
},
@@ -295,22 +295,25 @@ export default {
295295
users,
296296
logs,
297297
more,
298+
count,
298299
loading,
299300
finished,
300301
backInit,
301302
nextPage,
302303
isSearch,
303304
onQueryChange,
304305
handleCommand,
306+
searchDateDom,
305307
handleDateChange,
308+
searchKeywordDom,
306309
...toRefs(search),
307310
}
308311
},
309312
}
310313
</script>
311314
312315
<style lang="scss" scoped>
313-
.log >>> .el-button {
316+
.log /deep/ .el-button {
314317
padding-top: 10px;
315318
padding-bottom: 10px;
316319
}

0 commit comments

Comments
 (0)