|
@@ -0,0 +1,235 @@
|
|
|
+<template>
|
|
|
+ <div class="register">
|
|
|
+ <div class="one">注册</div>
|
|
|
+ <div class="two">
|
|
|
+ <el-form
|
|
|
+ ref="ruleFormRef"
|
|
|
+ :model="form"
|
|
|
+ :rules="rules"
|
|
|
+ label-width="100px"
|
|
|
+ class="form"
|
|
|
+ label-position="left"
|
|
|
+ >
|
|
|
+ <el-form-item label="注册类型" prop="type">
|
|
|
+ <el-radio-group v-model="form.type">
|
|
|
+ <el-radio label="普通用户" value="0"></el-radio>
|
|
|
+ <el-radio label="角色用户" value="1"></el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="角色选择" prop="role" v-if="form.type === '1'">
|
|
|
+ <el-checkbox-group v-model="form.role">
|
|
|
+ <el-checkbox
|
|
|
+ v-for="(item, index) in roleList"
|
|
|
+ :key="index"
|
|
|
+ :value="item.code"
|
|
|
+ name="type"
|
|
|
+ >{{ item.name }}</el-checkbox
|
|
|
+ >
|
|
|
+ </el-checkbox-group>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="板块选择" prop="plate">
|
|
|
+ <el-checkbox-group v-model="form.plate">
|
|
|
+ <el-checkbox
|
|
|
+ v-for="(item, index) in plateList"
|
|
|
+ :key="index"
|
|
|
+ :value="item.value"
|
|
|
+ name="type"
|
|
|
+ >{{ item.label }}</el-checkbox
|
|
|
+ >
|
|
|
+ </el-checkbox-group>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="姓名" prop="nick_name">
|
|
|
+ <el-input clearable v-model="form.nick_name" placeholder="请输入姓名/单位名称">
|
|
|
+ <template #prefix>
|
|
|
+ <el-icon>
|
|
|
+ <Avatar />
|
|
|
+ </el-icon>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="手机号" prop="phone">
|
|
|
+ <el-input clearable v-model="form.phone" placeholder="请输入手机号">
|
|
|
+ <template #prefix>
|
|
|
+ <el-icon>
|
|
|
+ <Iphone />
|
|
|
+ </el-icon>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="验证码" prop="checkCode">
|
|
|
+ <el-input
|
|
|
+ class="check-code-box"
|
|
|
+ v-model.number="form.checkCode"
|
|
|
+ placeholder="请输入验证码"
|
|
|
+ >
|
|
|
+ <template #prefix>
|
|
|
+ <el-icon>
|
|
|
+ <Message />
|
|
|
+ </el-icon>
|
|
|
+ </template>
|
|
|
+ <template v-slot:append>
|
|
|
+ <el-button :disabled="codeCd" @click="handleCaptcha('form')"
|
|
|
+ >获取验证码
|
|
|
+ <span v-if="codeCd">({{ long }})</span>
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="密码" prop="password">
|
|
|
+ <el-input
|
|
|
+ v-model="form.password"
|
|
|
+ type="password"
|
|
|
+ show-password
|
|
|
+ placeholder="请输入登录密码"
|
|
|
+ >
|
|
|
+ <template #prefix>
|
|
|
+ <el-icon>
|
|
|
+ <Unlock />
|
|
|
+ </el-icon>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-col :span="24" class="button">
|
|
|
+ <el-button type="primary" @click="submitForm(ruleFormRef)">注册</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="text">
|
|
|
+ <span>已有账号</span>
|
|
|
+ <span @click="toLogin">去登录</span>
|
|
|
+ </el-col>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script setup>
|
|
|
+import { cloneDeep } from 'lodash-es'
|
|
|
+// 路由
|
|
|
+const router = useRouter()
|
|
|
+// 接口
|
|
|
+import { UsersStore } from '@/store/api/user/user'
|
|
|
+const store = UsersStore()
|
|
|
+const form = ref({ role: ['User'] })
|
|
|
+// 表单验证
|
|
|
+const ruleFormRef = ref()
|
|
|
+const roleList = inject('roleList')
|
|
|
+// 用户协议
|
|
|
+const isAgree = ref(false)
|
|
|
+const plateList = ref([
|
|
|
+ { label: '汽车电子及新型汽车零部件', value: '0' },
|
|
|
+ { label: '精细化工及天然气化工', value: '1' },
|
|
|
+ { label: '农产品加工及绿色食品', value: '2' },
|
|
|
+ { label: '光电子及智能传感器', value: '3' },
|
|
|
+ { label: '车规级芯片及功率半导体器件', value: '4' },
|
|
|
+ { label: '新能源及动力电池', value: '5' },
|
|
|
+ { label: '生物基新材料', value: '6' },
|
|
|
+ { label: '人工智能及智能机器人', value: '7' },
|
|
|
+ { label: '碳纤维及复合材料', value: '8' },
|
|
|
+ { label: '遥感卫星及航天航空技术', value: '9' },
|
|
|
+ { label: '精密仪器及先进装备', value: '10' },
|
|
|
+ { label: '生物医药及先进医疗器械', value: '11' }
|
|
|
+])
|
|
|
+const validatePhoneNumber = (rule, value, callback) => {
|
|
|
+ const reg = /^1[3-9]\d{9}$/
|
|
|
+ if (!value) {
|
|
|
+ return callback(new Error('手机号不能为空'))
|
|
|
+ }
|
|
|
+ if (!reg.test(value)) {
|
|
|
+ return callback(new Error('请输入正确的手机号'))
|
|
|
+ }
|
|
|
+ callback()
|
|
|
+}
|
|
|
+const rules = reactive({
|
|
|
+ nick_name: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
|
|
+ phone: [{ required: true, validator: validatePhoneNumber, trigger: 'blur' }],
|
|
|
+ account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
|
|
|
+ password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
|
|
+ type: [{ required: true, message: '请选择注册类型', trigger: 'blur' }],
|
|
|
+ role: [{ required: true, message: '请选择角色', trigger: 'blur' }],
|
|
|
+ plate: [{ required: true, message: '请选择板块', trigger: 'blur' }],
|
|
|
+ checkCode: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
|
|
|
+})
|
|
|
+// 注册
|
|
|
+const submitForm = async (formEl) => {
|
|
|
+ if (!isAgree.value) {
|
|
|
+ ElMessage({
|
|
|
+ message: '请阅读并同意用户协议和隐私政策',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!formEl) return
|
|
|
+ await formEl.validate(async (valid, fields) => {
|
|
|
+ if (valid) {
|
|
|
+ const data = cloneDeep(form.value)
|
|
|
+ const user = await store.query({ account: data.nick_name })
|
|
|
+ if (user.total === 0) {
|
|
|
+ data.account = data.nick_name
|
|
|
+ data.gender = '0'
|
|
|
+ if (data.role === 'User') data.role = [data.role]
|
|
|
+ else data.role = ['User', ...[data.role]]
|
|
|
+ delete data.refpassword
|
|
|
+ delete data.checkCode
|
|
|
+ delete data.plate
|
|
|
+ delete data.type
|
|
|
+ const res = await store.create(data)
|
|
|
+ if (res.errcode === 0) {
|
|
|
+ ElMessage({
|
|
|
+ message: '注册用户成功,审核中请稍后登录',
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ router.push({ path: '/login' })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ElMessage({
|
|
|
+ message: '已有相同姓名或实验室名称 请重新输入!',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.log('error submit!', fields)
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+// 去登录
|
|
|
+const toLogin = () => {
|
|
|
+ router.push({ path: '/login', query: { status: '1' } })
|
|
|
+}
|
|
|
+</script>
|
|
|
+<style scoped lang="scss">
|
|
|
+.register {
|
|
|
+ .one {
|
|
|
+ text-align: center;
|
|
|
+ font-size: $global-font-size-24;
|
|
|
+ font-weight: bold;
|
|
|
+ padding: 5px 0 10px 0;
|
|
|
+ }
|
|
|
+ .two {
|
|
|
+ padding: 0 20px;
|
|
|
+ .button {
|
|
|
+ text-align: center;
|
|
|
+ padding: 10px 0;
|
|
|
+
|
|
|
+ :deep(.el-button) {
|
|
|
+ width: 100px !important;
|
|
|
+ height: 44px !important;
|
|
|
+ border: 0 !important;
|
|
|
+ border-radius: 50px !important;
|
|
|
+ color: #f8f8f8 !important;
|
|
|
+ font-size: $global-font-size-18 !important;
|
|
|
+ text-align: center !important;
|
|
|
+ line-height: 40px !important;
|
|
|
+ cursor: pointer !important;
|
|
|
+ font-family: PingFangSC-Regular !important;
|
|
|
+ background-color: $global-color-107 !important;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .text {
|
|
|
+ text-align: center;
|
|
|
+ font-size: $global-font-size-18;
|
|
|
+ span:last-child {
|
|
|
+ color: $global-color-107;
|
|
|
+ margin: 0 0 0 2px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|