Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
najiu-frontend
najiu-admin-template
Commits
46899aa3
Commit
46899aa3
authored
Jun 04, 2021
by
无木
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(demo): `switch` use in table
演示在table中渲染switch列并响应修改switch的动作
parent
41854121
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
7 deletions
+43
-7
system.ts
mock/demo/system.ts
+9
-0
system.ts
src/api/demo/system.ts
+4
-0
role.data.ts
src/views/demo/system/role/role.data.ts
+30
-7
No files found.
mock/demo/system.ts
View file @
46899aa3
...
...
@@ -152,6 +152,15 @@ export default [
return
resultPageSuccess
(
page
,
pageSize
,
roleList
);
},
},
{
url
:
'
/basic-api/system/setRoleStatus
'
,
timeout
:
500
,
method
:
'
post
'
,
response
:
({
query
})
=>
{
const
{
id
,
status
}
=
query
;
return
resultSuccess
({
id
,
status
});
},
},
{
url
:
'
/basic-api/system/getAllRoleList
'
,
timeout
:
100
,
...
...
src/api/demo/system.ts
View file @
46899aa3
...
...
@@ -15,6 +15,7 @@ import { defHttp } from '/@/utils/http/axios';
enum
Api
{
AccountList
=
'
/system/getAccountList
'
,
DeptList
=
'
/system/getDeptList
'
,
setRoleStatus
=
'
/system/setRoleStatus
'
,
MenuList
=
'
/system/getMenuList
'
,
RolePageList
=
'
/system/getRoleListByPage
'
,
GetAllRoleList
=
'
/system/getAllRoleList
'
,
...
...
@@ -34,3 +35,6 @@ export const getRoleListByPage = (params?: RolePageParams) =>
export
const
getAllRoleList
=
(
params
?:
RoleParams
)
=>
defHttp
.
get
<
RoleListGetResultModel
>
({
url
:
Api
.
GetAllRoleList
,
params
});
export
const
setRoleStatus
=
(
id
:
number
,
status
:
string
)
=>
defHttp
.
post
({
url
:
Api
.
setRoleStatus
,
params
:
{
id
,
status
}
});
src/views/demo/system/role/role.data.ts
View file @
46899aa3
import
{
BasicColumn
}
from
'
/@/components/Table
'
;
import
{
FormSchema
}
from
'
/@/components/Table
'
;
import
{
h
}
from
'
vue
'
;
import
{
Tag
}
from
'
ant-design-vue
'
;
import
{
Switch
}
from
'
ant-design-vue
'
;
import
{
setRoleStatus
}
from
'
/@/api/demo/system
'
;
import
{
useMessage
}
from
'
/@/hooks/web/useMessage
'
;
export
const
columns
:
BasicColumn
[]
=
[
{
title
:
'
角色名称
'
,
...
...
@@ -21,13 +24,33 @@ export const columns: BasicColumn[] = [
{
title
:
'
状态
'
,
dataIndex
:
'
status
'
,
width
:
8
0
,
width
:
12
0
,
customRender
:
({
record
})
=>
{
const
status
=
record
.
status
;
const
enable
=
~~
status
===
0
;
const
color
=
enable
?
'
green
'
:
'
red
'
;
const
text
=
enable
?
'
启用
'
:
'
停用
'
;
return
h
(
Tag
,
{
color
:
color
},
()
=>
text
);
if
(
!
Reflect
.
has
(
record
,
'
pendingStatus
'
))
{
record
.
pendingStatus
=
false
;
}
return
h
(
Switch
,
{
checked
:
record
.
status
===
'
1
'
,
checkedChildren
:
'
已启用
'
,
unCheckedChildren
:
'
已禁用
'
,
loading
:
record
.
pendingStatus
,
onChange
(
checked
:
boolean
)
{
record
.
pendingStatus
=
true
;
const
newStatus
=
checked
?
'
1
'
:
'
0
'
;
const
{
createMessage
}
=
useMessage
();
setRoleStatus
(
record
.
id
,
newStatus
)
.
then
(()
=>
{
record
.
status
=
newStatus
;
createMessage
.
success
(
`已成功修改角色状态`
);
})
.
catch
(()
=>
{
createMessage
.
error
(
'
修改角色状态失败
'
);
})
.
finally
(()
=>
{
record
.
pendingStatus
=
false
;
});
},
});
},
},
{
...
...
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