From 4f953ffc89fc95f83b152e914c5e65938b440f17 Mon Sep 17 00:00:00 2001
From: Xxxu <794772283@qq.com>
Date: 星期二, 07 七月 2020 10:03:02 +0800
Subject: [PATCH] 上传项目
---
src/views/modules/sys/user-add-or-update.vue | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 180 insertions(+), 0 deletions(-)
diff --git a/src/views/modules/sys/user-add-or-update.vue b/src/views/modules/sys/user-add-or-update.vue
new file mode 100644
index 0000000..e4dd4e7
--- /dev/null
+++ b/src/views/modules/sys/user-add-or-update.vue
@@ -0,0 +1,180 @@
+<template>
+ <el-dialog
+ :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-item>
+ <el-form-item label="瀵嗙爜" prop="password" :class="{ 'is-required': !dataForm.id }">
+ <el-input v-model="dataForm.password" type="password" placeholder="瀵嗙爜"></el-input>
+ </el-form-item>
+ <el-form-item label="纭瀵嗙爜" prop="comfirmPassword" :class="{ 'is-required': !dataForm.id }">
+ <el-input v-model="dataForm.comfirmPassword" type="password" placeholder="纭瀵嗙爜"></el-input>
+ </el-form-item>
+ <el-form-item label="閭" prop="email">
+ <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-form-item>
+ <el-form-item label="瑙掕壊" size="mini" prop="roleIdList">
+ <el-checkbox-group v-model="dataForm.roleIdList">
+ <el-checkbox v-for="role in roleList" :key="role.roleId" :label="role.roleId">{{ role.roleName }}</el-checkbox>
+ </el-checkbox-group>
+ </el-form-item>
+ <el-form-item label="鐘舵��" size="mini" prop="status">
+ <el-radio-group v-model="dataForm.status">
+ <el-radio :label="0">绂佺敤</el-radio>
+ <el-radio :label="1">姝e父</el-radio>
+ </el-radio-group>
+ </el-form-item>
+ </el-form>
+ <span slot="footer" class="dialog-footer">
+ <el-button @click="visible = false">鍙栨秷</el-button>
+ <el-button type="primary" @click="dataFormSubmit()">纭畾</el-button>
+ </span>
+ </el-dialog>
+</template>
+
+<script>
+ import { isEmail, isMobile } from '@/utils/validate'
+ export default {
+ data () {
+ var validatePassword = (rule, value, callback) => {
+ if (!this.dataForm.id && !/\S/.test(value)) {
+ callback(new Error('瀵嗙爜涓嶈兘涓虹┖'))
+ } else {
+ callback()
+ }
+ }
+ var validateComfirmPassword = (rule, value, callback) => {
+ if (!this.dataForm.id && !/\S/.test(value)) {
+ callback(new Error('纭瀵嗙爜涓嶈兘涓虹┖'))
+ } else if (this.dataForm.password !== value) {
+ callback(new Error('纭瀵嗙爜涓庡瘑鐮佽緭鍏ヤ笉涓�鑷�'))
+ } else {
+ callback()
+ }
+ }
+ var validateEmail = (rule, value, callback) => {
+ if (!isEmail(value)) {
+ callback(new Error('閭鏍煎紡閿欒'))
+ } else {
+ callback()
+ }
+ }
+ var validateMobile = (rule, value, callback) => {
+ if (!isMobile(value)) {
+ callback(new Error('鎵嬫満鍙锋牸寮忛敊璇�'))
+ } else {
+ callback()
+ }
+ }
+ return {
+ visible: false,
+ roleList: [],
+ dataForm: {
+ id: 0,
+ userName: '',
+ password: '',
+ comfirmPassword: '',
+ salt: '',
+ email: '',
+ mobile: '',
+ roleIdList: [],
+ status: 1
+ },
+ dataRule: {
+ userName: [
+ { required: true, message: '鐢ㄦ埛鍚嶄笉鑳戒负绌�', trigger: 'blur' }
+ ],
+ password: [
+ { validator: validatePassword, trigger: 'blur' }
+ ],
+ comfirmPassword: [
+ { validator: validateComfirmPassword, trigger: 'blur' }
+ ],
+ email: [
+ { required: true, message: '閭涓嶈兘涓虹┖', trigger: 'blur' },
+ { validator: validateEmail, trigger: 'blur' }
+ ],
+ mobile: [
+ { required: true, message: '鎵嬫満鍙蜂笉鑳戒负绌�', trigger: 'blur' },
+ { validator: validateMobile, trigger: 'blur' }
+ ]
+ }
+ }
+ },
+ methods: {
+ init (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
+ }
+ })
+ }
+ })
+ },
+ // 琛ㄥ崟鎻愪氦
+ dataFormSubmit () {
+ 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.$message({
+ message: '鎿嶄綔鎴愬姛',
+ type: 'success',
+ duration: 1500,
+ onClose: () => {
+ this.visible = false
+ this.$emit('refreshDataList')
+ }
+ })
+ } else {
+ this.$message.error(data.msg)
+ }
+ })
+ }
+ })
+ }
+ }
+ }
+</script>
--
Gitblit v1.9.3