Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
front-backend
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
front-backend
Commits
e69750a5
Commit
e69750a5
authored
Sep 28, 2019
by
moxun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
简化数据字典,支持单组件内多字典同时使用,全局混入,组件不配置字典时,不对data附加dict属性
parent
ae71ad97
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
8 deletions
+65
-8
src/components/dict/Dict.js
+29
-0
src/components/dict/index.js
+29
-0
src/main.js
+2
-0
src/views/system/user/index.vue
+5
-8
No files found.
src/components/dict/Dict.js
0 → 100644
View file @
e69750a5
import
Vue
from
'vue'
import
{
get
as
getDictDetail
}
from
'@/api/dictDetail'
export
default
class
Dict
{
constructor
(
dict
)
{
this
.
dict
=
dict
}
async
init
(
names
,
completeCallback
)
{
if
(
names
===
undefined
||
name
===
null
)
{
throw
new
Error
(
'need dict names'
)
}
const
ps
=
[]
names
.
forEach
(
n
=>
{
Vue
.
set
(
this
.
dict
.
dict
,
n
,
{})
Vue
.
set
(
this
.
dict
.
label
,
n
,
{})
Vue
.
set
(
this
.
dict
,
n
,
[])
ps
.
push
(
getDictDetail
(
n
).
then
(
data
=>
{
this
.
dict
[
n
].
splice
(
0
,
0
,
...
data
.
content
)
data
.
content
.
forEach
(
d
=>
{
Vue
.
set
(
this
.
dict
.
dict
[
n
],
d
.
value
,
d
)
Vue
.
set
(
this
.
dict
.
label
[
n
],
d
.
value
,
d
.
label
)
})
}))
})
await
Promise
.
all
(
ps
)
completeCallback
()
}
}
src/components/dict/index.js
0 → 100644
View file @
e69750a5
import
Dict
from
'./Dict'
const
install
=
function
(
Vue
)
{
Vue
.
mixin
({
data
()
{
if
(
this
.
$options
.
dicts
instanceof
Array
)
{
const
dict
=
{
dict
:
{},
label
:
{},
}
return
{
dict
,
}
}
return
{}
},
created
()
{
if
(
this
.
$options
.
dicts
instanceof
Array
)
{
new
Dict
(
this
.
dict
).
init
(
this
.
$options
.
dicts
,
()
=>
{
this
.
$nextTick
(()
=>
{
this
.
$emit
(
'dictReady'
)
})
})
}
},
})
}
export
default
{
install
}
src/main.js
View file @
e69750a5
...
...
@@ -11,6 +11,7 @@ import '@/styles/index.scss' // global css
import
App
from
'./App'
import
router
from
'./router/routers'
import
permission
from
'./components/permission'
import
dict
from
'./components/dict'
import
store
from
'./store'
import
'@/icons'
// icon
...
...
@@ -19,6 +20,7 @@ import './router/index' // permission control
Vue
.
use
(
mavonEditor
)
Vue
.
use
(
permission
)
Vue
.
use
(
dict
)
Vue
.
use
(
ElementUI
,
{
locale
})
Vue
.
config
.
productionTip
=
false
...
...
src/views/system/user/index.vue
View file @
e69750a5
<
template
>
<div
class=
"app-container"
>
<!--form 组件-->
<eForm
ref=
"form"
:is-add=
"isAdd"
:dicts=
"dicts"
/>
<eForm
ref=
"form"
:is-add=
"isAdd"
:dicts=
"dict
.user_statu
s"
/>
<el-row
:gutter=
"20"
>
<!--部门数据-->
<el-col
:xs=
"9"
:sm=
"6"
:md=
"4"
:lg=
"4"
:xl=
"4"
>
...
...
@@ -53,9 +53,7 @@
</el-table-column>
<el-table-column
label=
"状态"
align=
"center"
>
<
template
slot-scope=
"scope"
>
<div
v-for=
"item in dicts"
:key=
"item.id"
>
<el-tag
v-if=
"scope.row.enabled.toString() === item.value"
:type=
"scope.row.enabled ? '' : 'info'"
>
{{
item
.
label
}}
</el-tag>
</div>
<el-tag>
{{
dict
.
label
.
user_status
[
scope
.
row
.
enabled
]
}}
</el-tag>
</
template
>
</el-table-column>
<el-table-column
:show-overflow-tooltip=
"true"
prop=
"createTime"
label=
"创建日期"
>
...
...
@@ -97,7 +95,6 @@
<
script
>
import
checkPermission
from
'@/utils/permission'
import
initData
from
'@/mixins/initData'
import
initDict
from
'@/mixins/initDict'
import
{
del
,
downloadUser
}
from
'@/api/user'
import
{
getDepts
}
from
'@/api/dept'
import
{
parseTime
,
downloadFile
}
from
'@/utils/index'
...
...
@@ -105,7 +102,9 @@ import eForm from './form'
export
default
{
name
:
'User'
,
components
:
{
eForm
},
mixins
:
[
initData
,
initDict
],
mixins
:
[
initData
],
// 设置数据字典
dicts
:
[
'user_status'
],
data
()
{
return
{
height
:
document
.
documentElement
.
clientHeight
-
180
+
'px;'
,
isAdd
:
false
,
...
...
@@ -125,8 +124,6 @@ export default {
this
.
getDeptDatas
()
this
.
$nextTick
(()
=>
{
this
.
init
()
// 加载数据字典
this
.
getDict
(
'user_status'
)
})
},
mounted
:
function
()
{
...
...
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