You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
15 KiB
1 lines
15 KiB
{"ast":null,"code":"import { toDisplayString as _toDisplayString, createElementVNode as _createElementVNode, createTextVNode as _createTextVNode, resolveComponent as _resolveComponent, normalizeClass as _normalizeClass, withCtx as _withCtx, createVNode as _createVNode, openBlock as _openBlock, createBlock as _createBlock, createCommentVNode as _createCommentVNode, createElementBlock as _createElementBlock } from \"vue\";\nconst _hoisted_1 = {\n class: \"login-container\"\n};\nconst _hoisted_2 = {\n class: \"login-box\"\n};\nconst _hoisted_3 = {\n class: \"title\"\n};\nconst _hoisted_4 = {\n class: \"toggle-buttons\"\n};\nexport function render(_ctx, _cache, $props, $setup, $data, $options) {\n const _component_el_button = _resolveComponent(\"el-button\");\n const _component_el_input = _resolveComponent(\"el-input\");\n const _component_el_form_item = _resolveComponent(\"el-form-item\");\n const _component_el_form = _resolveComponent(\"el-form\");\n return _openBlock(), _createElementBlock(\"div\", _hoisted_1, [_createElementVNode(\"div\", _hoisted_2, [_createElementVNode(\"h2\", _hoisted_3, _toDisplayString($setup.isRegister ? '用户注册' : '欢迎登录'), 1 /* TEXT */), _createElementVNode(\"div\", _hoisted_4, [_createVNode(_component_el_button, {\n class: _normalizeClass(['toggle-btn', !$setup.isRegister && 'active']),\n onClick: _cache[0] || (_cache[0] = $event => $setup.isRegister = false)\n }, {\n default: _withCtx(() => _cache[5] || (_cache[5] = [_createTextVNode(\"登录\")])),\n _: 1 /* STABLE */\n }, 8 /* PROPS */, [\"class\"]), _createVNode(_component_el_button, {\n class: _normalizeClass(['toggle-btn', $setup.isRegister && 'active']),\n onClick: _cache[1] || (_cache[1] = $event => $setup.isRegister = true)\n }, {\n default: _withCtx(() => _cache[6] || (_cache[6] = [_createTextVNode(\"注册\")])),\n _: 1 /* STABLE */\n }, 8 /* PROPS */, [\"class\"])]), _createVNode(_component_el_form, {\n ref: \"formRef\",\n model: $setup.form,\n rules: $setup.rules,\n \"label-width\": \"0\",\n class: \"login-form\"\n }, {\n default: _withCtx(() => [_createVNode(_component_el_form_item, {\n prop: \"username\"\n }, {\n default: _withCtx(() => [_createVNode(_component_el_input, {\n modelValue: $setup.form.username,\n \"onUpdate:modelValue\": _cache[2] || (_cache[2] = $event => $setup.form.username = $event),\n placeholder: \"请输入用户名\",\n \"prefix-icon\": \"User\"\n }, null, 8 /* PROPS */, [\"modelValue\"])]),\n _: 1 /* STABLE */\n }), _createVNode(_component_el_form_item, {\n prop: \"password\"\n }, {\n default: _withCtx(() => [_createVNode(_component_el_input, {\n modelValue: $setup.form.password,\n \"onUpdate:modelValue\": _cache[3] || (_cache[3] = $event => $setup.form.password = $event),\n type: \"password\",\n placeholder: \"请输入密码\",\n \"prefix-icon\": \"Lock\",\n \"show-password\": \"\"\n }, null, 8 /* PROPS */, [\"modelValue\"])]),\n _: 1 /* STABLE */\n }), $setup.isRegister ? (_openBlock(), _createBlock(_component_el_form_item, {\n key: 0,\n prop: \"email\"\n }, {\n default: _withCtx(() => [_createVNode(_component_el_input, {\n modelValue: $setup.form.email,\n \"onUpdate:modelValue\": _cache[4] || (_cache[4] = $event => $setup.form.email = $event),\n placeholder: \"请输入邮箱\",\n \"prefix-icon\": \"Message\"\n }, null, 8 /* PROPS */, [\"modelValue\"])]),\n _: 1 /* STABLE */\n })) : _createCommentVNode(\"v-if\", true), _createVNode(_component_el_form_item, null, {\n default: _withCtx(() => [_createVNode(_component_el_button, {\n type: \"primary\",\n class: \"submit-btn\",\n loading: $setup.loading,\n onClick: $setup.handleSubmit\n }, {\n default: _withCtx(() => [_createTextVNode(_toDisplayString($setup.isRegister ? '注册' : '登录'), 1 /* TEXT */)]),\n _: 1 /* STABLE */\n }, 8 /* PROPS */, [\"loading\"])]),\n _: 1 /* STABLE */\n })]),\n _: 1 /* STABLE */\n }, 8 /* PROPS */, [\"model\"])])]);\n}","map":{"version":3,"names":["class","_createElementBlock","_hoisted_1","_createElementVNode","_hoisted_2","_hoisted_3","_toDisplayString","$setup","isRegister","_hoisted_4","_createVNode","_component_el_button","_normalizeClass","onClick","_cache","$event","default","_withCtx","_createTextVNode","_","_component_el_form","ref","model","form","rules","_component_el_form_item","prop","_component_el_input","modelValue","username","placeholder","password","type","_createBlock","key","email","_createCommentVNode","loading","handleSubmit"],"sources":["D:\\language\\VScode\\Front-end logistics\\src\\views\\login\\index.vue"],"sourcesContent":["<template>\r\n <div class=\"login-container\">\r\n <div class=\"login-box\">\r\n <h2 class=\"title\">{{ isRegister ? '用户注册' : '欢迎登录' }}</h2>\r\n \r\n <div class=\"toggle-buttons\">\r\n <el-button \r\n :class=\"['toggle-btn', !isRegister && 'active']\"\r\n @click=\"isRegister = false\"\r\n >登录</el-button>\r\n <el-button \r\n :class=\"['toggle-btn', isRegister && 'active']\"\r\n @click=\"isRegister = true\"\r\n >注册</el-button>\r\n </div>\r\n \r\n <el-form \r\n ref=\"formRef\"\r\n :model=\"form\"\r\n :rules=\"rules\"\r\n label-width=\"0\"\r\n class=\"login-form\"\r\n >\r\n <el-form-item prop=\"username\">\r\n <el-input\r\n v-model=\"form.username\"\r\n placeholder=\"请输入用户名\"\r\n prefix-icon=\"User\"\r\n />\r\n </el-form-item>\r\n \r\n <el-form-item prop=\"password\">\r\n <el-input\r\n v-model=\"form.password\"\r\n type=\"password\"\r\n placeholder=\"请输入密码\"\r\n prefix-icon=\"Lock\"\r\n show-password\r\n />\r\n </el-form-item>\r\n \r\n <el-form-item v-if=\"isRegister\" prop=\"email\">\r\n <el-input\r\n v-model=\"form.email\"\r\n placeholder=\"请输入邮箱\"\r\n prefix-icon=\"Message\"\r\n />\r\n </el-form-item>\r\n \r\n <el-form-item>\r\n <el-button \r\n type=\"primary\" \r\n class=\"submit-btn\"\r\n :loading=\"loading\"\r\n @click=\"handleSubmit\"\r\n >\r\n {{ isRegister ? '注册' : '登录' }}\r\n </el-button>\r\n </el-form-item>\r\n </el-form>\r\n </div>\r\n </div>\r\n</template>\r\n\r\n<script setup>\r\nimport { ref, reactive } from 'vue'\r\nimport { useRouter } from 'vue-router'\r\nimport { useStore } from 'vuex'\r\nimport { ElMessage } from 'element-plus'\r\nimport { User, Lock, Message } from '@element-plus/icons-vue'\r\nimport { login, register } from '@/api/auth'\r\n\r\nconst router = useRouter()\r\nconst store = useStore()\r\nconst formRef = ref(null)\r\nconst isRegister = ref(false)\r\nconst loading = ref(false)\r\n\r\nconst form = reactive({\r\n username: '',\r\n password: '',\r\n email: ''\r\n})\r\n\r\nconst rules = {\r\n username: [\r\n { required: true, message: '请输入用户名', trigger: 'blur' },\r\n { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }\r\n ],\r\n password: [\r\n { required: true, message: '请输入密码', trigger: 'blur' },\r\n { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }\r\n ],\r\n email: [\r\n { required: true, message: '请输入邮箱地址', trigger: 'blur' },\r\n { \r\n type: 'email', \r\n message: '请输入正确的邮箱地址', \r\n trigger: ['blur', 'change'] \r\n },\r\n {\r\n pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/,\r\n message: '邮箱格式不正确',\r\n trigger: ['blur', 'change']\r\n }\r\n ]\r\n}\r\n\r\nconst handleSubmit = async () => {\r\n if (!formRef.value) return\r\n \r\n try {\r\n await formRef.value.validate()\r\n loading.value = true\r\n \r\n if (isRegister.value) {\r\n // 检查邮箱格式\r\n const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/\r\n if (!emailRegex.test(form.email)) {\r\n ElMessage.error('邮箱格式不正确')\r\n return\r\n }\r\n\r\n const res = await register(form)\r\n if (res.code === 200) {\r\n ElMessage.success(res.message || '注册成功,请登录')\r\n isRegister.value = false\r\n formRef.value.resetFields()\r\n form.username = form.username\r\n }\r\n } else {\r\n const res = await login(form)\r\n if (res.code === 200) {\r\n console.log('登录返回的完整数据:', res.data)\r\n \r\n // 保存用户信息和 token\r\n store.commit('setUserInfo', {\r\n userId: res.data.userId,\r\n username: res.data.username,\r\n roles: res.data.roleCodes // 使用返回的角色数组\r\n })\r\n store.commit('setToken', res.data.token)\r\n ElMessage.success('登录成功')\r\n \r\n // 根据角色重定向到不同页面\r\n if (res.data.roleCodes.includes('ROLE_ADMIN')) {\r\n router.push('/admin/orders')\r\n } else if (res.data.roleCodes.includes('ROLE_LOGISTICS_ADMIN')) {\r\n router.push('/admin/orders')\r\n } else if (res.data.roleCodes.includes('ROLE_WAREHOUSE_ADMIN')) {\r\n router.push('/orders/create')\r\n } else if (res.data.roleCodes.includes('ROLE_USER')) {\r\n router.push('/orders/my')\r\n } else {\r\n ElMessage.error('未知的用户角色')\r\n store.dispatch('logout')\r\n router.push('/login')\r\n }\r\n }\r\n }\r\n } catch (error) {\r\n console.error('操作失败:', error)\r\n ElMessage.error(error.message || '操作失败,请重试')\r\n } finally {\r\n loading.value = false\r\n }\r\n}\r\n\r\n// 注册图标组件\r\nconst icons = {\r\n User,\r\n Lock,\r\n Message\r\n}\r\n</script>\r\n\r\n<style scoped>\r\n.login-container {\r\n height: 100vh;\r\n display: flex;\r\n justify-content: center;\r\n align-items: center;\r\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\r\n}\r\n\r\n.login-box {\r\n width: 420px;\r\n padding: 40px;\r\n background: rgba(255, 255, 255, 0.95);\r\n border-radius: 16px;\r\n box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);\r\n backdrop-filter: blur(10px);\r\n transition: all 0.3s ease;\r\n animation: fadeIn 0.6s ease-out;\r\n}\r\n\r\n.login-box:hover {\r\n transform: translateY(-5px);\r\n box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);\r\n}\r\n\r\n.title {\r\n text-align: center;\r\n color: #409EFF;\r\n font-size: 28px;\r\n margin-bottom: 30px;\r\n font-weight: 600;\r\n text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\r\n}\r\n\r\n.toggle-buttons {\r\n display: flex;\r\n justify-content: center;\r\n margin-bottom: 30px;\r\n gap: 20px;\r\n}\r\n\r\n.toggle-btn {\r\n width: 100px;\r\n transition: all 0.3s ease;\r\n}\r\n\r\n.toggle-btn.active {\r\n background: #409EFF;\r\n color: white;\r\n font-weight: 500;\r\n transform: scale(1.05);\r\n}\r\n\r\n.login-form {\r\n margin-top: 20px;\r\n}\r\n\r\n.login-form :deep(.el-input__wrapper) {\r\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);\r\n border-radius: 8px;\r\n transition: all 0.3s ease;\r\n}\r\n\r\n.login-form :deep(.el-input__wrapper:hover) {\r\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);\r\n}\r\n\r\n.login-form :deep(.el-input__wrapper.is-focus) {\r\n box-shadow: 0 0 0 1px #409EFF;\r\n}\r\n\r\n.submit-btn {\r\n width: 100%;\r\n height: 44px;\r\n font-size: 16px;\r\n font-weight: 500;\r\n letter-spacing: 1px;\r\n background: linear-gradient(45deg, #409EFF, #36cccb);\r\n border: none;\r\n margin-top: 20px;\r\n transition: all 0.3s ease;\r\n}\r\n\r\n.submit-btn:hover {\r\n transform: translateY(-2px);\r\n box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);\r\n background: linear-gradient(45deg, #36cccb, #409EFF);\r\n}\r\n\r\n/* 添加动画效果 */\r\n@keyframes fadeIn {\r\n from {\r\n opacity: 0;\r\n transform: translateY(20px);\r\n }\r\n to {\r\n opacity: 1;\r\n transform: translateY(0);\r\n }\r\n}\r\n\r\n/* 响应式设计 */\r\n@media (max-width: 480px) {\r\n .login-box {\r\n width: 90%;\r\n padding: 30px 20px;\r\n }\r\n}\r\n</style> "],"mappings":";;EACOA,KAAK,EAAC;AAAiB;;EACrBA,KAAK,EAAC;AAAW;;EAChBA,KAAK,EAAC;AAAO;;EAEZA,KAAK,EAAC;AAAgB;;;;;;uBAJ/BC,mBAAA,CA4DM,OA5DNC,UA4DM,GA3DJC,mBAAA,CA0DM,OA1DNC,UA0D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