index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <div class="loginform">
  7. <el-col :span="24" class="tab">
  8. <el-col
  9. :span="6"
  10. class="title"
  11. @click="toTab(0)"
  12. :class="[activeName == '0' ? 'tab0' : 'tab1']"
  13. >个人登录</el-col
  14. >
  15. <el-col
  16. :span="6"
  17. class="title"
  18. @click="toTab(1)"
  19. :class="[activeName == '1' ? 'tab0' : 'tab1']"
  20. >管理登录</el-col
  21. >
  22. </el-col>
  23. <el-col :span="24" class="content" v-show="activeName == '0'">
  24. <el-form
  25. ref="ruleFormRef"
  26. :model="form"
  27. :rules="rules"
  28. label-width="60px"
  29. class="form"
  30. label-position="left"
  31. >
  32. <el-form-item label="账号" prop="account">
  33. <el-input clearable v-model="form.account" placeholder="请输入账号">
  34. <template #prefix>
  35. <el-icon>
  36. <User />
  37. </el-icon>
  38. </template>
  39. </el-input>
  40. </el-form-item>
  41. <el-form-item label="密码" prop="password">
  42. <el-input
  43. v-model="form.password"
  44. type="password"
  45. show-password
  46. placeholder="请输入登录密码"
  47. >
  48. <template #prefix>
  49. <el-icon>
  50. <Unlock />
  51. </el-icon>
  52. </template>
  53. </el-input>
  54. </el-form-item>
  55. <el-col :span="24" class="remark">
  56. <span>其他方式登录</span>
  57. <span>忘记密码?</span>
  58. </el-col>
  59. <el-col :span="24" class="button">
  60. <el-button type="primary" @click="submitForm(ruleFormRef)">登录</el-button>
  61. </el-col>
  62. <el-col :span="24" class="agree">
  63. <span>登录即表示您同意</span>
  64. <span @click="dialog = true">《{{ siteInfo.zhTitle }}使用协议》</span>
  65. </el-col>
  66. <el-col :span="24" class="other">
  67. <span>还没有账号?</span>
  68. &nbsp;&nbsp;
  69. <span @click="toRegister">去注册</span>
  70. </el-col>
  71. </el-form>
  72. </el-col>
  73. <el-col :span="24" class="content" v-show="activeName == '1'">
  74. <el-form
  75. ref="ruleFormRef"
  76. :model="form"
  77. :rules="rules"
  78. label-width="60px"
  79. class="form"
  80. label-position="left"
  81. >
  82. <el-form-item label="账号" prop="account">
  83. <el-input clearable v-model="form.account" placeholder="请输入账号">
  84. <template #prefix>
  85. <el-icon>
  86. <User />
  87. </el-icon>
  88. </template>
  89. </el-input>
  90. </el-form-item>
  91. <el-form-item label="密码" prop="password">
  92. <el-input
  93. v-model="form.password"
  94. type="password"
  95. show-password
  96. placeholder="请输入登录密码"
  97. >
  98. <template #prefix>
  99. <el-icon>
  100. <Unlock />
  101. </el-icon>
  102. </template>
  103. </el-input>
  104. </el-form-item>
  105. <el-col :span="24" class="remark">
  106. <span>其他方式登录</span>
  107. <span>忘记密码?</span>
  108. </el-col>
  109. <el-col :span="24" class="button">
  110. <el-button type="primary" @click="submitForm(ruleFormRef)">登录</el-button>
  111. </el-col>
  112. <el-col :span="24" class="agree">
  113. <span>登录即表示您同意</span>
  114. <span @click="dialog = true">《{{ siteInfo.zhTitle }}使用协议》</span>
  115. </el-col>
  116. <el-col :span="24" class="other">
  117. <span>还没有账号?</span>
  118. &nbsp; &nbsp;
  119. <span @click="toRegister">去注册</span>
  120. </el-col>
  121. </el-form>
  122. </el-col>
  123. </div>
  124. </el-col>
  125. </el-col>
  126. </el-row>
  127. <el-dialog v-model="dialog" title="使用协议">
  128. <div v-html="configInfo.agreement"></div>
  129. </el-dialog>
  130. </div>
  131. </template>
  132. <script setup>
  133. // 基础
  134. import { siteInfo } from '@/layout/site'
  135. import { cloneDeep } from 'lodash-es'
  136. // 接口
  137. import { DesignStore } from '@/store/api/platform/design'
  138. import { LoginStore } from '@/store/api/login'
  139. const loginStore = LoginStore()
  140. const designStore = DesignStore()
  141. const $checkRes = inject('$checkRes')
  142. // 路由
  143. const router = useRouter()
  144. // 加载中
  145. const loading = ref(false)
  146. const dialog = ref(false)
  147. const form = ref({})
  148. const ruleFormRef = ref()
  149. const rules = reactive({
  150. account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
  151. password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
  152. })
  153. const activeName = ref(0)
  154. const configInfo = ref({})
  155. // 请求
  156. onMounted(async () => {
  157. loading.value = true
  158. search()
  159. loading.value = false
  160. })
  161. const search = async () => {
  162. // 基础设置
  163. const result = await designStore.query({})
  164. if ($checkRes(result)) configInfo.value = result.data[0] || {}
  165. }
  166. // 选择
  167. const toTab = async (active) => {
  168. activeName.value = active
  169. form.value = {}
  170. }
  171. // 登录
  172. const submitForm = async (formEl) => {
  173. if (!formEl) return
  174. await formEl.validate(async (valid, fields) => {
  175. if (valid) {
  176. const data = cloneDeep(form.value)
  177. if (activeName.value == 0) data.type = 'User'
  178. else data.type = 'Admin'
  179. const res = await loginStore.login(data)
  180. if (res.errcode == '0') {
  181. ElMessage({ message: `登录成功`, type: 'success' })
  182. localStorage.setItem('token', res.data)
  183. // 路由
  184. router.push({ path: '/' })
  185. } else {
  186. ElMessage({ message: `${res.errmsg}`, type: 'error' })
  187. }
  188. } else {
  189. console.log('error submit!', fields)
  190. }
  191. })
  192. }
  193. // 去注册
  194. const toRegister = () => {
  195. router.push({ path: '/register' })
  196. }
  197. </script>
  198. <style scoped lang="scss">
  199. .main {
  200. .one {
  201. background-image: url(@/assets/loginbg.jpeg);
  202. background-position: center center;
  203. background-repeat: no-repeat;
  204. height: calc(100vh - 22.6vh);
  205. width: 100%;
  206. background-size: cover;
  207. display: flex;
  208. justify-content: space-evenly;
  209. .loginform {
  210. position: absolute;
  211. top: 50%;
  212. left: 50%;
  213. height: 380px;
  214. padding: 20px 85px;
  215. background: hsla(0, 0%, 100%, 0.6);
  216. box-shadow: 0 0 30px 0 rgba(51, 51, 51, 0.2);
  217. -webkit-transform: translate(-50%, -50%);
  218. transform: translate(-50%, -50%);
  219. border-top: 10px solid #1492ff;
  220. .tab {
  221. display: flex;
  222. align-items: center;
  223. justify-content: center;
  224. .title {
  225. text-align: center;
  226. margin: 0 40px;
  227. font-family: PingFangSC-Semibold !important;
  228. font-size: 20px;
  229. letter-spacing: -0.14px;
  230. line-height: 32px;
  231. font-weight: bold;
  232. }
  233. .tab0 {
  234. color: #1492ff;
  235. border-bottom: 2px solid;
  236. border-bottom-color: #1492ff;
  237. padding-bottom: 10px;
  238. }
  239. .tab1 {
  240. color: #333333;
  241. padding-bottom: 10px;
  242. }
  243. }
  244. .content {
  245. margin: 35px 50px 0px;
  246. .remark {
  247. display: flex;
  248. justify-content: space-between;
  249. span {
  250. cursor: pointer;
  251. font-family: PingFangSC-Regular;
  252. font-size: 14px;
  253. color: #333333;
  254. letter-spacing: -0.09px;
  255. text-align: right;
  256. line-height: 32px;
  257. }
  258. span:hover {
  259. color: #2374ff;
  260. }
  261. }
  262. .button {
  263. padding: 10px 0;
  264. :deep(.el-button) {
  265. width: 100% !important;
  266. height: 44px !important;
  267. border: 0 !important;
  268. color: #f8f8f8 !important;
  269. font-size: 16px !important;
  270. text-align: center !important;
  271. line-height: 40px !important;
  272. cursor: pointer !important;
  273. font-family: PingFangSC-Regular !important;
  274. background-color: #1492ff !important;
  275. }
  276. }
  277. .agree {
  278. padding: 0 0 30px 0;
  279. color: #999;
  280. font-size: 12px;
  281. span:last-child {
  282. color: #2374ff;
  283. }
  284. }
  285. .other {
  286. text-align: center;
  287. font-family: PingFangSC-Regular;
  288. font-size: 14px;
  289. color: #333333;
  290. span:last-child {
  291. color: #2374ff;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. }
  298. </style>