update 管理员列表
This commit is contained in:
parent
1d5aba6455
commit
21d7df2237
@ -4,11 +4,21 @@ import http from '../utils/http'
|
||||
* 管理员列表
|
||||
*/
|
||||
// 获取管理员列表
|
||||
export const apiGetSysUserList = params => {
|
||||
export const apiSysUserList = params => {
|
||||
return http({ url: '/renren-fast-server/sys/user/list', method: 'get', params })
|
||||
}
|
||||
|
||||
// 获取管理员列表
|
||||
export const apiGetSysRoleSelect = params => {
|
||||
export const apiSysRoleSelect = params => {
|
||||
return http({ url: '/renren-fast-server/sys/role/select', method: 'get', params })
|
||||
}
|
||||
|
||||
// 新增管理员
|
||||
export const apiSysUserSave = data => {
|
||||
return http({ url: '/renren-fast-server/sys/user/save', method: 'post', data })
|
||||
}
|
||||
|
||||
// 编辑管理员
|
||||
export const apiSysUserUpdate = data => {
|
||||
return http({ url: '/renren-fast-server/sys/user/update', method: 'post', data })
|
||||
}
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
:title="!dataForm.id ? '新增' : '修改'"
|
||||
:close-on-click-modal="false"
|
||||
:visible.sync="visible">
|
||||
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
|
||||
<el-form-item label="用户名" prop="userName">
|
||||
<el-input v-model="dataForm.userName" placeholder="登录帐号"></el-input>
|
||||
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="handleConfirm()" label-width="80px">
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input v-model="dataForm.username" placeholder="登录帐号"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password" :class="{ 'is-required': !dataForm.id }">
|
||||
<el-input v-model="dataForm.password" type="password" placeholder="密码"></el-input>
|
||||
@ -17,7 +17,7 @@
|
||||
<el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号" prop="mobile">
|
||||
<el-input v-model="dataForm.mobile" placeholder="手机号"></el-input>
|
||||
<el-input v-model="dataForm.mobile" placeholder="手机号" maxlength="11"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="角色" size="mini" prop="roleIdList">
|
||||
<el-checkbox-group v-model="dataForm.roleIdList">
|
||||
@ -33,14 +33,14 @@
|
||||
</el-form>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
|
||||
<el-button type="primary" @click="handleConfirm()">确定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { isEmail, isMobile } from '@/utils/validate'
|
||||
import { apiGetSysRoleSelect } from '@/api/api_sys'
|
||||
import { apiSysRoleSelect, apiSysUserSave, apiSysUserUpdate } from '@/api/api_sys'
|
||||
import { apiGetUserInfo } from '@/api/api_user'
|
||||
|
||||
export default {
|
||||
@ -80,7 +80,7 @@
|
||||
roleList: [],
|
||||
dataForm: {
|
||||
id: 0,
|
||||
userName: '',
|
||||
username: '',
|
||||
password: '',
|
||||
comfirmPassword: '',
|
||||
salt: '',
|
||||
@ -90,7 +90,7 @@
|
||||
status: 1
|
||||
},
|
||||
dataRule: {
|
||||
userName: [{ required: true, message: '用户名不能为空', trigger: 'blur' }],
|
||||
username: [{ required: true, message: '用户名不能为空', trigger: 'blur' }],
|
||||
password: [{ validator: validatePassword, trigger: 'blur' }],
|
||||
comfirmPassword: [{ validator: validateComfirmPassword, trigger: 'blur' }],
|
||||
email: [
|
||||
@ -101,53 +101,29 @@
|
||||
{ required: true, message: '手机号不能为空', trigger: 'blur' },
|
||||
{ validator: validateMobile, trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
},
|
||||
apiName: '' // 新增/编辑接口名
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
init1 (id) {
|
||||
this.dataForm.id = id || 0
|
||||
this.$http({
|
||||
url: this.$http.adornUrl('/sys/role/select'),
|
||||
method: 'get',
|
||||
params: this.$http.adornParams()
|
||||
}).then(({data}) => {
|
||||
this.roleList = data && data.code === 0 ? data.list : []
|
||||
}).then(() => {
|
||||
this.visible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].resetFields()
|
||||
})
|
||||
}).then(() => {
|
||||
if (this.dataForm.id) {
|
||||
this.$http({
|
||||
url: this.$http.adornUrl(`/sys/user/info/${this.dataForm.id}`),
|
||||
method: 'get',
|
||||
params: this.$http.adornParams()
|
||||
}).then(({data}) => {
|
||||
if (data && data.code === 0) {
|
||||
this.dataForm.userName = data.user.username
|
||||
this.dataForm.salt = data.user.salt
|
||||
this.dataForm.email = data.user.email
|
||||
this.dataForm.mobile = data.user.mobile
|
||||
this.dataForm.roleIdList = data.user.roleIdList
|
||||
this.dataForm.status = data.user.status
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
init (id) {
|
||||
if (id) {
|
||||
this.dataForm.id = id || 0
|
||||
this.handleEdit()
|
||||
this.apiName = apiSysUserUpdate
|
||||
} else {
|
||||
this.handleAdd()
|
||||
this.apiName = apiSysUserSave
|
||||
}
|
||||
},
|
||||
// 新增/修改
|
||||
// 新增
|
||||
handleAdd (id) {
|
||||
this.dataForm.id = id || 0
|
||||
apiGetSysRoleSelect({}).then(res => {
|
||||
apiSysRoleSelect({}).then(res => {
|
||||
this.roleList = res && res.code === 0 ? res.list : []
|
||||
this.visible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].resetFields()
|
||||
})
|
||||
}).then(() => {
|
||||
this.handleEdit()
|
||||
})
|
||||
},
|
||||
// 编辑
|
||||
@ -155,7 +131,7 @@
|
||||
apiGetUserInfo({}, `/${this.dataForm.id}`).then(res => {
|
||||
if (res && res.code === 0) {
|
||||
this.$nextTick(() => {
|
||||
this.dataForm.userName = res.user.username
|
||||
this.dataForm.username = res.user.username
|
||||
this.dataForm.salt = res.user.salt
|
||||
this.dataForm.email = res.user.email
|
||||
this.dataForm.mobile = res.user.mobile
|
||||
@ -166,25 +142,12 @@
|
||||
}
|
||||
})
|
||||
},
|
||||
// 表单提交
|
||||
dataFormSubmit () {
|
||||
// 提交
|
||||
handleConfirm () {
|
||||
this.$refs['dataForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.$http({
|
||||
url: this.$http.adornUrl(`/sys/user/${!this.dataForm.id ? 'save' : 'update'}`),
|
||||
method: 'post',
|
||||
data: this.$http.adornData({
|
||||
'userId': this.dataForm.id || undefined,
|
||||
'username': this.dataForm.userName,
|
||||
'password': this.dataForm.password,
|
||||
'salt': this.dataForm.salt,
|
||||
'email': this.dataForm.email,
|
||||
'mobile': this.dataForm.mobile,
|
||||
'status': this.dataForm.status,
|
||||
'roleIdList': this.dataForm.roleIdList
|
||||
})
|
||||
}).then(({data}) => {
|
||||
if (data && data.code === 0) {
|
||||
this.apiName(this.dataForm).then(res => {
|
||||
if (res && res.code === 0) {
|
||||
this.$message({
|
||||
message: '操作成功',
|
||||
type: 'success',
|
||||
@ -195,7 +158,7 @@
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.$message.error(data.msg)
|
||||
this.$message.error(res.msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
<script>
|
||||
import AddOrUpdate from './user-add-or-update'
|
||||
import { apiGetSysUserList } from '../../../api/api_sys'
|
||||
import { apiSysUserList } from '../../../api/api_sys'
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
@ -71,7 +71,7 @@
|
||||
methods: {
|
||||
// 获取数据列表
|
||||
handleGetTableList () {
|
||||
apiGetSysUserList({
|
||||
apiSysUserList({
|
||||
'page': this.pageIndex,
|
||||
'limit': this.pageSize,
|
||||
'username': this.dataForm.userName
|
||||
@ -105,7 +105,7 @@
|
||||
handleAddOrUpdate (id) {
|
||||
this.addOrUpdateVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.addOrUpdate.handleAdd(id)
|
||||
this.$refs.addOrUpdate.init(id)
|
||||
})
|
||||
},
|
||||
// 删除
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user