Skip to content

Commit ee04bb0

Browse files
authored
Merge pull request #2100 from bypanghu/dict
fix:添加字典列表搜索,支持中英文搜索.添加字典详情搜索
2 parents 2e224a8 + 1c4ef73 commit ee04bb0

File tree

13 files changed

+511
-304
lines changed

13 files changed

+511
-304
lines changed

server/api/v1/system/sys_dictionary.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/flipped-aurora/gin-vue-admin/server/global"
55
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
66
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
7+
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
78
"github.com/gin-gonic/gin"
89
"go.uber.org/zap"
910
)
@@ -116,10 +117,17 @@ func (s *DictionaryApi) FindSysDictionary(c *gin.Context) {
116117
// @Security ApiKeyAuth
117118
// @accept application/json
118119
// @Produce application/json
120+
// @Param data query request.SysDictionarySearch true "字典 name 或者 type"
119121
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysDictionary列表,返回包括列表,总数,页码,每页数量"
120122
// @Router /sysDictionary/getSysDictionaryList [get]
121123
func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
122-
list, err := dictionaryService.GetSysDictionaryInfoList()
124+
var dictionary request.SysDictionarySearch
125+
err := c.ShouldBindQuery(&dictionary)
126+
if err != nil {
127+
response.FailWithMessage(err.Error(), c)
128+
return
129+
}
130+
list, err := dictionaryService.GetSysDictionaryInfoList(c, dictionary)
123131
if err != nil {
124132
global.GVA_LOG.Error("获取失败!", zap.Error(err))
125133
response.FailWithMessage("获取失败", c)

server/config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ cors:
268268
allow-headers: Content-Type,AccessToken,X-CSRF-Token, Authorization, Token,X-Token,X-User-Id
269269
allow-methods: POST, GET
270270
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type
271-
272271
allow-credentials: true # 布尔值
273272
- allow-origin: example2.com
274273
allow-headers: content-type
@@ -280,4 +279,4 @@ mcp:
280279
version: v1.0.0
281280
sse_path: /sse
282281
message_path: /message
283-
url_prefix: ''
282+
url_prefix: ''

server/model/common/response/response.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const (
1818
)
1919

2020
func Result(code int, data interface{}, msg string, c *gin.Context) {
21-
// 开始时间
2221
c.JSON(http.StatusOK, Response{
2322
code,
2423
data,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package request
2+
3+
type SysDictionarySearch struct {
4+
Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"` // 字典名(中)
5+
}

server/service/system/sys_dictionary.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package system
22

33
import (
44
"errors"
5+
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
6+
"github.com/gin-gonic/gin"
57

68
"github.com/flipped-aurora/gin-vue-admin/server/global"
79
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
@@ -105,8 +107,12 @@ func (dictionaryService *DictionaryService) GetSysDictionary(Type string, Id uin
105107
//@param: info request.SysDictionarySearch
106108
//@return: err error, list interface{}, total int64
107109

108-
func (dictionaryService *DictionaryService) GetSysDictionaryInfoList() (list interface{}, err error) {
110+
func (dictionaryService *DictionaryService) GetSysDictionaryInfoList(c *gin.Context, req request.SysDictionarySearch) (list interface{}, err error) {
109111
var sysDictionarys []system.SysDictionary
110-
err = global.GVA_DB.Find(&sysDictionarys).Error
112+
query := global.GVA_DB.WithContext(c)
113+
if req.Name != "" {
114+
query = query.Where("name LIKE ? OR type LIKE ?", "%"+req.Name+"%", "%"+req.Name+"%")
115+
}
116+
err = query.Find(&sysDictionarys).Error
111117
return sysDictionarys, err
112118
}

web/.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ VITE_SERVER_PORT = 8888
44
VITE_BASE_API = /api
55
VITE_FILE_API = /api
66
VITE_BASE_PATH = http://127.0.0.1
7-
VITE_POSITION = close
7+
VITE_POSITION = open
88
VITE_EDITOR = code
99
// VITE_EDITOR = webstorm 如果使用webstorm开发且要使用dom定位到代码行功能 请先自定添加 webstorm到环境变量 再将VITE_EDITOR值修改为webstorm
1010
// 如果使用docker-compose开发模式,设置为下面的地址或本机主机IP

web/src/App.vue

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
2-
<div id="app" class="bg-gray-50 text-slate-700 dark:text-slate-500 dark:bg-slate-800">
2+
<div
3+
id="app"
4+
class="bg-gray-50 text-slate-700 !dark:text-slate-500 dark:bg-slate-800"
5+
>
36
<el-config-provider :locale="zhCn">
47
<router-view />
58
<Application />
@@ -8,36 +11,36 @@
811
</template>
912

1013
<script setup>
11-
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
12-
import Application from '@/components/application/index.vue'
13-
import { useAppStore } from '@/pinia'
14+
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
15+
import Application from '@/components/application/index.vue'
16+
import { useAppStore } from '@/pinia'
1417
15-
useAppStore()
16-
defineOptions({
17-
name: 'App'
18-
})
18+
useAppStore()
19+
defineOptions({
20+
name: 'App'
21+
})
1922
</script>
2023
<style lang="scss">
21-
// 引入初始化样式
22-
#app {
23-
height: 100vh;
24-
overflow: hidden;
25-
font-weight: 400 !important;
26-
}
24+
// 引入初始化样式
25+
#app {
26+
height: 100vh;
27+
overflow: hidden;
28+
font-weight: 400 !important;
29+
}
2730
28-
.el-button {
29-
font-weight: 400 !important;
30-
}
31+
.el-button {
32+
font-weight: 400 !important;
33+
}
3134
32-
.gva-body-h {
33-
min-height: calc(100% - 3rem);
34-
}
35+
.gva-body-h {
36+
min-height: calc(100% - 3rem);
37+
}
3538
36-
.gva-container {
37-
height: calc(100% - 2.5rem);
38-
}
39+
.gva-container {
40+
height: calc(100% - 2.5rem);
41+
}
3942
40-
.gva-container2 {
41-
height: calc(100% - 4.5rem);
42-
}
43+
.gva-container2 {
44+
height: calc(100% - 4.5rem);
45+
}
4346
</style>

web/src/directive/clickOutSide.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export default {
2+
install: (app) => {
3+
app.directive('click-outside', {
4+
mounted(el, binding) {
5+
const handler = (e) => {
6+
// 如果绑定的元素包含事件目标,或元素已经被移除,则不触发
7+
if (!el || el.contains(e.target) || e.target === el) return
8+
// 支持函数或对象 { handler: fn, exclude: [el1, el2], capture: true }
9+
const value = binding.value
10+
if (value && typeof value === 'object') {
11+
if (
12+
value.exclude &&
13+
value.exclude.some(
14+
(ex) => ex && ex.contains && ex.contains(e.target)
15+
)
16+
)
17+
return
18+
if (typeof value.handler === 'function') value.handler(e)
19+
} else if (typeof value === 'function') {
20+
value(e)
21+
}
22+
}
23+
24+
// 存到 el 上,便于解绑
25+
el.__clickOutsideHandler__ = handler
26+
27+
// 延迟注册,避免 mounted 时触发(比如当点击就是触发绑定动作时)
28+
setTimeout(() => {
29+
document.addEventListener('mousedown', handler)
30+
document.addEventListener('touchstart', handler)
31+
}, 0)
32+
},
33+
unmounted(el) {
34+
const h = el.__clickOutsideHandler__
35+
if (h) {
36+
document.removeEventListener('mousedown', h)
37+
document.removeEventListener('touchstart', h)
38+
delete el.__clickOutsideHandler__
39+
}
40+
}
41+
})
42+
}
43+
}

web/src/main.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import './style/element_visiable.scss'
22
import 'element-plus/theme-chalk/dark/css-vars.css'
3-
import 'uno.css';
3+
import 'uno.css'
44
import { createApp } from 'vue'
55
import ElementPlus from 'element-plus'
66

@@ -12,11 +12,19 @@ import router from '@/router/index'
1212
import '@/permission'
1313
import run from '@/core/gin-vue-admin.js'
1414
import auth from '@/directive/auth'
15+
import clickOutSide from '@/directive/clickOutSide'
1516
import { store } from '@/pinia'
1617
import App from './App.vue'
1718

1819
const app = createApp(App)
1920
app.config.productionTip = false
2021

21-
app.use(run).use(ElementPlus).use(store).use(auth).use(router).mount('#app')
22+
app
23+
.use(run)
24+
.use(ElementPlus)
25+
.use(store)
26+
.use(auth)
27+
.use(clickOutSide)
28+
.use(router)
29+
.mount('#app')
2230
export default app

0 commit comments

Comments
 (0)