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
12 KiB
1 lines
12 KiB
{"ast":null,"code":"import { createTextVNode as _createTextVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode, createElementVNode as _createElementVNode, openBlock as _openBlock, createBlock as _createBlock, createCommentVNode as _createCommentVNode, toDisplayString as _toDisplayString, 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: \"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(\"div\", _hoisted_3, [_createVNode(_component_el_button, {\n type: $setup.isRegister ? '' : 'primary',\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 */, [\"type\"]), _createVNode(_component_el_button, {\n type: $setup.isRegister ? 'primary' : '',\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 */, [\"type\"])]), _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","_createVNode","_component_el_button","type","$setup","isRegister","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","_createBlock","key","email","_createCommentVNode","loading","handleSubmit","_toDisplayString"],"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 <div class=\"toggle-buttons\">\r\n <el-button \r\n :type=\"isRegister ? '' : 'primary'\"\r\n @click=\"isRegister = false\"\r\n >登录</el-button>\r\n <el-button \r\n :type=\"isRegister ? 'primary' : ''\"\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 { type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }\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 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-color: #f5f5f5;\r\n}\r\n\r\n.login-box {\r\n width: 400px;\r\n padding: 30px;\r\n background: white;\r\n border-radius: 8px;\r\n box-shadow: 0 2px 12px 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.login-form {\r\n margin-top: 20px;\r\n}\r\n\r\n.submit-btn {\r\n width: 100%;\r\n}\r\n</style> "],"mappings":";;EACOA,KAAK,EAAC;AAAiB;;EACrBA,KAAK,EAAC;AAAW;;EACfA,KAAK,EAAC;AAAgB;;;;;;uBAF/BC,mBAAA,CA0DM,OA1DNC,UA0DM,GAzDJC,mBAAA,CAwDM,OAxDNC,UAwDM,GAvDJD,mBAAA,CASM,OATNE,UASM,GARJC,YAAA,CAGeC,oBAAA;IAFZC,IAAI,EAAEC,MAAA,CAAAC,UAAU;IAChBC,OAAK,EAAAC,MAAA,QAAAA,MAAA,MAAAC,MAAA,IAAEJ,MAAA,CAAAC,UAAU;;IAN5BI,OAAA,EAAAC,QAAA,CAOS,MAAEH,MAAA,QAAAA,MAAA,OAPXI,gBAAA,CAOS,IAAE,E;IAPXC,CAAA;+BAQQX,YAAA,CAGeC,oBAAA;IAFZC,IAAI,EAAEC,MAAA,CAAAC,UAAU;IAChBC,OAAK,EAAAC,MAAA,QAAAA,MAAA,MAAAC,MAAA,IAAEJ,MAAA,CAAAC,UAAU;;IAV5BI,OAAA,EAAAC,QAAA,CAWS,MAAEH,MAAA,QAAAA,MAAA,OAXXI,gBAAA,CAWS,IAAE,E;IAXXC,CAAA;iCAcMX,YAAA,CA2CUY,kBAAA;IA1CRC,GAAG,EAA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