Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sts网站
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyang
sts网站
Commits
5ec5e1a6
Commit
5ec5e1a6
authored
Jul 20, 2022
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化字典数据使用store存取
parent
1f0e7427
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
86 additions
and
1 deletion
+86
-1
index.js
ruoyi-ui/src/components/DictData/index.js
+29
-1
getters.js
ruoyi-ui/src/store/getters.js
+1
-0
index.js
ruoyi-ui/src/store/index.js
+2
-0
dict.js
ruoyi-ui/src/store/modules/dict.js
+50
-0
data.vue
ruoyi-ui/src/views/system/dict/data.vue
+3
-0
index.vue
ruoyi-ui/src/views/system/dict/index.vue
+1
-0
No files found.
ruoyi-ui/src/components/DictData/index.js
View file @
5ec5e1a6
import
Vue
from
'vue'
import
store
from
'@/store'
import
DataDict
from
'@/utils/dict'
import
{
getDicts
as
getDicts
}
from
'@/api/system/dict/data'
function
searchDictByKey
(
dict
,
key
)
{
if
(
key
==
null
&&
key
==
""
)
{
return
null
}
try
{
for
(
let
i
=
0
;
i
<
dict
.
length
;
i
++
)
{
if
(
dict
[
i
].
key
==
key
)
{
return
dict
[
i
].
value
}
}
}
catch
(
e
)
{
return
null
}
}
function
install
()
{
Vue
.
use
(
DataDict
,
{
metas
:
{
...
...
@@ -9,7 +25,19 @@ function install() {
labelField
:
'dictLabel'
,
valueField
:
'dictValue'
,
request
(
dictMeta
)
{
return
getDicts
(
dictMeta
.
type
).
then
(
res
=>
res
.
data
)
const
storeDict
=
searchDictByKey
(
store
.
getters
.
dict
,
dictMeta
.
type
)
if
(
storeDict
)
{
return
new
Promise
(
resolve
=>
{
resolve
(
storeDict
)
})
}
else
{
return
new
Promise
((
resolve
,
reject
)
=>
{
getDicts
(
dictMeta
.
type
).
then
(
res
=>
{
store
.
dispatch
(
'dict/setDict'
,
{
key
:
dictMeta
.
type
,
value
:
res
.
data
})
resolve
(
res
.
data
)
}).
catch
(
error
=>
{
reject
(
error
)
})
})
}
},
},
},
...
...
ruoyi-ui/src/store/getters.js
View file @
5ec5e1a6
...
...
@@ -2,6 +2,7 @@ const getters = {
sidebar
:
state
=>
state
.
app
.
sidebar
,
size
:
state
=>
state
.
app
.
size
,
device
:
state
=>
state
.
app
.
device
,
dict
:
state
=>
state
.
dict
.
dict
,
visitedViews
:
state
=>
state
.
tagsView
.
visitedViews
,
cachedViews
:
state
=>
state
.
tagsView
.
cachedViews
,
token
:
state
=>
state
.
user
.
token
,
...
...
ruoyi-ui/src/store/index.js
View file @
5ec5e1a6
import
Vue
from
'vue'
import
Vuex
from
'vuex'
import
app
from
'./modules/app'
import
dict
from
'./modules/dict'
import
user
from
'./modules/user'
import
tagsView
from
'./modules/tagsView'
import
permission
from
'./modules/permission'
...
...
@@ -12,6 +13,7 @@ Vue.use(Vuex)
const
store
=
new
Vuex
.
Store
({
modules
:
{
app
,
dict
,
user
,
tagsView
,
permission
,
...
...
ruoyi-ui/src/store/modules/dict.js
0 → 100644
View file @
5ec5e1a6
const
state
=
{
dict
:
new
Array
()
}
const
mutations
=
{
SET_DICT
:
(
state
,
{
key
,
value
})
=>
{
if
(
key
!==
null
&&
key
!==
""
)
{
state
.
dict
.
push
({
key
:
key
,
value
:
value
})
}
},
REMOVE_DICT
:
(
state
,
key
)
=>
{
try
{
for
(
let
i
=
0
;
i
<
state
.
dict
.
length
;
i
++
)
{
if
(
state
.
dict
[
i
].
key
==
key
)
{
state
.
dict
.
splice
(
i
,
i
)
return
true
}
}
}
catch
(
e
)
{
}
},
CLEAN_DICT
:
(
state
)
=>
{
state
.
dict
=
new
Array
()
}
}
const
actions
=
{
// 设置字典
setDict
({
commit
},
data
)
{
commit
(
'SET_DICT'
,
data
)
},
// 删除字典
removeDict
({
commit
},
key
)
{
commit
(
'REMOVE_DICT'
,
key
)
},
// 清空字典
cleanDict
({
commit
})
{
commit
(
'CLEAN_DICT'
)
}
}
export
default
{
namespaced
:
true
,
state
,
mutations
,
actions
}
ruoyi-ui/src/views/system/dict/data.vue
View file @
5ec5e1a6
...
...
@@ -364,12 +364,14 @@ export default {
if
(
valid
)
{
if
(
this
.
form
.
dictCode
!=
undefined
)
{
updateData
(
this
.
form
).
then
(
response
=>
{
this
.
$store
.
dispatch
(
'dict/removeDict'
,
this
.
queryParams
.
dictType
);
this
.
$modal
.
msgSuccess
(
"修改成功"
);
this
.
open
=
false
;
this
.
getList
();
});
}
else
{
addData
(
this
.
form
).
then
(
response
=>
{
this
.
$store
.
dispatch
(
'dict/removeDict'
,
this
.
queryParams
.
dictType
);
this
.
$modal
.
msgSuccess
(
"新增成功"
);
this
.
open
=
false
;
this
.
getList
();
...
...
@@ -386,6 +388,7 @@ export default {
}).
then
(()
=>
{
this
.
getList
();
this
.
$modal
.
msgSuccess
(
"删除成功"
);
this
.
$store
.
dispatch
(
'dict/removeDict'
,
this
.
queryParams
.
dictType
);
}).
catch
(()
=>
{});
},
/** 导出按钮操作 */
...
...
ruoyi-ui/src/views/system/dict/index.vue
View file @
5ec5e1a6
...
...
@@ -339,6 +339,7 @@ export default {
handleRefreshCache
()
{
refreshCache
().
then
(()
=>
{
this
.
$modal
.
msgSuccess
(
"刷新成功"
);
this
.
$store
.
dispatch
(
'dict/cleanDict'
);
});
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment