Skip to content

Commit

Permalink
add user
Browse files Browse the repository at this point in the history
  • Loading branch information
qiang committed Jan 3, 2020
1 parent 4d03fd0 commit 65c65ee
Show file tree
Hide file tree
Showing 17 changed files with 798 additions and 129 deletions.
55 changes: 50 additions & 5 deletions ctrl/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,64 @@ func Index(c *gin.Context) {
response.ShowData(c, data)
return
}
func Edit(c *gin.Context) {
func Create(c *gin.Context) {
data,err:=request.GetJson(c)
if err != nil {
response.ShowError(c, "fail")
return
}
if _, ok := data["id"]; !ok {
if _, ok := data["name"]; !ok {
response.ShowError(c, "fail")
return
}
if _, ok := data["nickname"]; !ok {
response.ShowError(c, "fail")
return
}
if _, ok := data["password"]; !ok {
response.ShowError(c, "fail")
return
}
if _, ok := data["repassword"]; !ok {
response.ShowError(c, "fail")
return
}
if _, ok := data["status"]; !ok {
response.ShowError(c, "fail")
return
}
if _, ok := data["avatar"]; !ok {
response.ShowError(c, "fail")
return
}
userModel := models.SystemUser{};
userModel.Nickname=data["name"].(string)
has:=userModel.GetRow()
if has {
response.ShowError(c, "name_exists")
return
}
userModel.Password=data["password"].(string)
if userModel.Password!=data["repassword"].(string){
response.ShowError(c, "nickname_exists")
return
}
userModel.Salt =common.GetRandomBoth(4)
userModel.Password = common.Sha1En(userModel.Password+userModel.Salt)
userModel.Name = data["name"].(string)
if _, ok := data["status"]; ok {

}




}
func Edit(c *gin.Context) {
data,err:=request.GetJson(c)
if err != nil {
response.ShowError(c, "fail")
return
}
if _, ok := data["id"]; !ok {
response.ShowError(c, "fail")
return
}
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func main() {
r.PUT("/menu",menu.Edit)
r.DELETE("/menu",menu.Delete)
r.GET("/user",user.Index)
r.POST("/user/edit",user.Index)
r.GET("/user/create",user.Create)
r.POST("/user/edit",user.Edit)
r.POST("/role/delete/:name",role.DeleteRole)
r.POST("/role/update",role.UpdateRole)
r.POST("/role/add",role.AddRole)
Expand Down
1 change: 1 addition & 0 deletions modules/lang/cn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ var cn = map[string]string{
"params_error": "参数错误",
"nologin": "未登录",
"user_error": "用户不存在",
"name_exists": "用户名已存在",
"role_error": "角色不存在",
}
8 changes: 8 additions & 0 deletions vue-element-admin/src/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ export function fetchList(data) {
baseURL: httphost + '/user'
})
}
export function createUser(data) {
return request({
url: '',
method: 'post',
data,
baseURL: httphost + '/user/create'
})
}
35 changes: 33 additions & 2 deletions vue-element-admin/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export const asyncRoutes = [
// path: 'edit/:id(\\d+)',
// component: () => import('@/views/example/edit'),
// name: 'EditArticle',
// meta: { title: 'editArticle', noCache: true, activeMenu: '/example/list' },
// meta: { title: 'editArticle', noCache: true },
// hidden: true
// },
// {
Expand All @@ -238,7 +238,38 @@ export const asyncRoutes = [
// }
// ]
// },
//
// {
// path: '/system/user',
// component: Layout,
// redirect: '/example/list',
// name: 'Example',
// meta: {
// title: 'example',
// icon: 'example'
// },
// children: [
// {
// path: 'create',
// component: () => import('@/views/system/user/create/index'),
// name: 'CreateArticle',
// meta: { title: 'createArticle', icon: 'edit' }
// },
// {
// path: 'edit/:id(\\d+)',
// component: () => import('@/views/system/user/edit/index'),
// name: 'EditArticle',
// meta: { title: 'editArticle' },
// hidden: true
// },
// {
// path: 'list',
// component: () => import('@/views/system/user/list/index'),
// name: 'ArticleList',
// meta: { title: 'articleList', icon: 'list' }
// }
// ]
// },

// {
// path: '/tab',
// component: Layout,
Expand Down
6 changes: 3 additions & 3 deletions vue-element-admin/src/views/system/menu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
<el-input v-model="Menu.sort" placeholder="Menu sort"/>
</el-form-item>

<el-form-item label="总显示">
<el-form-item label="是否缓存">
<el-switch
v-model="Menu.alwaysshow"
v-model="Menu.meta_nocache"
:on-value="true"
:off-value="false"
></el-switch>
Expand Down Expand Up @@ -214,7 +214,7 @@ export default {
this.checkStrictly = true
this.Menu = deepClone(scope.row)
this.Menu.status = (this.Menu.status === 1) ? true : false
this.Menu.alwaysshow = (this.Menu.alwaysshow ===1) ? true : false
this.Menu.meta_nocache = (this.Menu.meta_nocache ===1) ? true : false
this.Menu.hidden = (this.Menu.hidden ===1) ? true : false
this.$nextTick(() => {
this.$refs['formData'].clearValidate()
Expand Down
32 changes: 32 additions & 0 deletions vue-element-admin/src/views/system/role/components/SwitchRoles.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div>
<div style="margin-bottom:15px;">
{{ $t('permission.roles') }}: {{ roles }}
</div>
{{ $t('permission.switchRoles') }}:
<el-radio-group v-model="switchRoles">
<el-radio-button label="editor" />
<el-radio-button label="admin" />
</el-radio-group>
</div>
</template>

<script>
export default {
computed: {
roles() {
return this.$store.getters.roles
},
switchRoles: {
get() {
return this.roles[0]
},
set(val) {
this.$store.dispatch('user/changeRoles', val).then(() => {
this.$emit('change')
})
}
}
}
}
</script>
111 changes: 111 additions & 0 deletions vue-element-admin/src/views/system/role/directive.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<template>
<div class="app-container">
<switch-roles @change="handleRolesChange" />
<div :key="key" style="margin-top:30px;">
<div>
<span v-permission="['admin']" class="permission-alert">
Only
<el-tag class="permission-tag" size="small">admin</el-tag> can see this
</span>
<el-tag v-permission="['admin']" class="permission-sourceCode" type="info">
v-permission="['admin']"
</el-tag>
</div>

<div>
<span v-permission="['editor']" class="permission-alert">
Only
<el-tag class="permission-tag" size="small">editor</el-tag> can see this
</span>
<el-tag v-permission="['editor']" class="permission-sourceCode" type="info">
v-permission="['editor']"
</el-tag>
</div>

<div>
<span v-permission="['admin','editor']" class="permission-alert">
Both
<el-tag class="permission-tag" size="small">admin</el-tag> and
<el-tag class="permission-tag" size="small">editor</el-tag> can see this
</span>
<el-tag v-permission="['admin','editor']" class="permission-sourceCode" type="info">
v-permission="['admin','editor']"
</el-tag>
</div>
</div>

<div :key="'checkPermission'+key" style="margin-top:60px;">
<aside>
{{ $t('permission.tips') }}
<br> e.g.
</aside>

<el-tabs type="border-card" style="width:550px;">
<el-tab-pane v-if="checkPermission(['admin'])" label="Admin">
Admin can see this
<el-tag class="permission-sourceCode" type="info">
v-if="checkPermission(['admin'])"
</el-tag>
</el-tab-pane>

<el-tab-pane v-if="checkPermission(['editor'])" label="Editor">
Editor can see this
<el-tag class="permission-sourceCode" type="info">
v-if="checkPermission(['editor'])"
</el-tag>
</el-tab-pane>

<el-tab-pane v-if="checkPermission(['admin','editor'])" label="Admin-OR-Editor">
Both admin or editor can see this
<el-tag class="permission-sourceCode" type="info">
v-if="checkPermission(['admin','editor'])"
</el-tag>
</el-tab-pane>
</el-tabs>
</div>
</div>
</template>

<script>
import permission from '@/directive/permission/index.js' // 权限判断指令
import checkPermission from '@/utils/permission' // 权限判断函数
import SwitchRoles from './components/SwitchRoles'
export default {
name: 'DirectivePermission',
components: { SwitchRoles },
directives: { permission },
data() {
return {
key: 1 // 为了能每次切换权限的时候重新初始化指令
}
},
methods: {
checkPermission,
handleRolesChange() {
this.key++
}
}
}
</script>

<style lang="scss" scoped>
.app-container {
/deep/ .permission-alert {
width: 320px;
margin-top: 15px;
background-color: #f0f9eb;
color: #67c23a;
padding: 8px 16px;
border-radius: 4px;
display: inline-block;
}
/deep/ .permission-sourceCode {
margin-left: 15px;
}
/deep/ .permission-tag {
background-color: #ecf5ff;
}
}
</style>

19 changes: 19 additions & 0 deletions vue-element-admin/src/views/system/role/page.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<div class="app-container">
<switch-roles @change="handleRolesChange" />
</div>
</template>

<script>
import SwitchRoles from './components/SwitchRoles'
export default {
name: 'PagePermission',
components: { SwitchRoles },
methods: {
handleRolesChange() {
this.$router.push({ path: '/permission/index?' + +new Date() })
}
}
}
</script>
Loading

0 comments on commit 65c65ee

Please sign in to comment.