login.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="register">
  3. <div class="one">登录</div>
  4. <div class="two">
  5. <el-col :span="24" class="tab">
  6. <el-col :span="9" class="title" @click="toTab(0)" :class="[activeName == '0' ? 'tab0' : 'tab1']">用户名密码登录</el-col>
  7. <el-col :span="9" class="title" @click="toTab(1)" :class="[activeName == '1' ? 'tab0' : 'tab1']">短信快捷登录</el-col>
  8. </el-col>
  9. <div v-if="activeName == '0'">
  10. <el-form ref="ruleFormRef" :model="form" :rules="rules" label-width="70px" class="form" label-position="left">
  11. <el-col :span="24" class="content">
  12. <el-form-item label="账号" prop="account">
  13. <el-input size="large" clearable v-model="form.account" placeholder="请输入账号">
  14. <template #prefix>
  15. <el-icon>
  16. <User />
  17. </el-icon>
  18. </template>
  19. </el-input>
  20. </el-form-item>
  21. <el-form-item label="密码" prop="password">
  22. <el-input size="large" v-model="form.password" type="password" show-password placeholder="请输入登录密码">
  23. <template #prefix>
  24. <el-icon>
  25. <Unlock />
  26. </el-icon>
  27. </template>
  28. </el-input>
  29. </el-form-item>
  30. <el-col :span="24" class="remark">
  31. <span>忘记密码?</span>
  32. </el-col>
  33. <el-col :span="24" class="button">
  34. <el-button type="primary" @click="submitForm(ruleFormRef)">登录</el-button>
  35. </el-col>
  36. <el-col :span="24" class="text">
  37. <span>没有账号</span>
  38. <span @click="toRegister">立即注册</span>
  39. </el-col>
  40. <div class="checks_box">
  41. <el-checkbox v-model="isAgree" size="large" class="checks_inpt" />
  42. <div class="checks_text">
  43. <span>我已阅读并同意</span>
  44. <span @click="toAgree"> 服务条款、隐私政策</span>
  45. </div>
  46. </div>
  47. </el-col>
  48. </el-form>
  49. </div>
  50. <div v-else>
  51. <el-form ref="ruleFormRef" :model="form" :rules="rules" label-width="70px" class="form" label-position="left">
  52. <el-col :span="24" class="content">
  53. <el-form-item label="手机号" prop="phone">
  54. <el-input size="large" clearable v-model="form.phone" placeholder="请输入手机号">
  55. <template #prefix>
  56. <el-icon>
  57. <Iphone />
  58. </el-icon>
  59. </template>
  60. </el-input>
  61. </el-form-item>
  62. <el-form-item label="验证码" prop="checkCode">
  63. <el-input size="large" class="check-code-box" v-model.number="form.checkCode" placeholder="请输入验证码">
  64. <template #prefix>
  65. <el-icon>
  66. <Message />
  67. </el-icon>
  68. </template>
  69. <template v-slot:append>
  70. <el-button :disabled="codeCd" @click="handleCaptcha('form')"
  71. >获取验证码
  72. <span v-if="codeCd">({{ long }})</span>
  73. </el-button>
  74. </template>
  75. </el-input>
  76. </el-form-item>
  77. <el-col :span="24" class="remark">
  78. <span>忘记密码?</span>
  79. </el-col>
  80. <el-col :span="24" class="button">
  81. <el-button type="primary" @click="submitForm(ruleFormRef)">登录</el-button>
  82. </el-col>
  83. <el-col :span="24" class="text">
  84. <span>没有账号</span>
  85. <span @click="toRegister">立即注册</span>
  86. </el-col>
  87. <div class="checks_box">
  88. <el-checkbox v-model="isAgree" size="large" class="checks_inpt" />
  89. <div class="checks_text">
  90. <span>我已阅读并同意</span>
  91. <span @click="toAgree"> 服务条款、隐私政策</span>
  92. </div>
  93. </div>
  94. </el-col>
  95. </el-form>
  96. </div>
  97. </div>
  98. </div>
  99. <el-dialog v-model="dialog" title="使用协议">
  100. <div v-html="configInfo.agreement"></div>
  101. </el-dialog>
  102. </template>
  103. <script setup>
  104. // 基础
  105. import { cloneDeep } from 'lodash-es'
  106. // 接口
  107. import { LoginStore } from '@/store/api/login'
  108. const loginStore = LoginStore()
  109. // 路由
  110. const router = useRouter()
  111. const activeName = ref(0)
  112. const configInfo = inject('configInfo')
  113. // 用户协议
  114. const isAgree = ref(false)
  115. const dialog = ref(false)
  116. // 加载中
  117. const form = ref({})
  118. const ruleFormRef = ref()
  119. const rules = reactive({
  120. account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
  121. password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
  122. })
  123. // 选择
  124. const toTab = async (active) => {
  125. activeName.value = active
  126. form.value = {}
  127. }
  128. // 登录
  129. const submitForm = async (formEl) => {
  130. if (!isAgree.value) {
  131. ElMessage({
  132. message: '请阅读并同意用户协议和隐私政策',
  133. type: 'warning'
  134. })
  135. return
  136. }
  137. if (!formEl) return
  138. await formEl.validate(async (valid, fields) => {
  139. if (valid) {
  140. const data = cloneDeep(form.value)
  141. data.type = 'User'
  142. const res = await loginStore.login(data)
  143. if (res.errcode == '0') {
  144. ElMessage({ message: `登录成功`, type: 'success' })
  145. localStorage.setItem('token', res.data)
  146. // 路由
  147. router.push({ path: '/' })
  148. } else {
  149. ElMessage({ message: `${res.errmsg}`, type: 'error' })
  150. }
  151. } else {
  152. console.log('error submit!', fields)
  153. }
  154. })
  155. }
  156. // 去注册
  157. const toRegister = () => {
  158. router.push({ path: '/login', query: { status: '0' } })
  159. }
  160. // 查看隐私协议
  161. const toAgree = () => {
  162. dialog.value = !dialog.value
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. .register {
  167. .one {
  168. text-align: center;
  169. font-size: $global-font-size-24;
  170. font-weight: bold;
  171. padding: 5px 0 10px 0;
  172. }
  173. .two {
  174. .tab {
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. margin: 10px;
  179. .title {
  180. text-align: center;
  181. margin: 0 40px;
  182. font-family: PingFangSC-Semibold !important;
  183. font-size: $global-font-size-20;
  184. letter-spacing: -0.14px;
  185. line-height: 32px;
  186. font-weight: bold;
  187. }
  188. .tab0 {
  189. color: #1492ff;
  190. border-bottom: 2px solid;
  191. border-bottom-color: #1492ff;
  192. padding-bottom: 10px;
  193. }
  194. .tab1 {
  195. color: #333333;
  196. padding-bottom: 10px;
  197. }
  198. }
  199. .content {
  200. padding: 20px;
  201. .remark {
  202. cursor: default;
  203. text-align: right;
  204. margin: 10px 0;
  205. color: #9a9a9a;
  206. }
  207. .button {
  208. text-align: center;
  209. padding: 10px 0;
  210. :deep(.el-button) {
  211. width: 100px !important;
  212. height: 44px !important;
  213. border: 0 !important;
  214. border-radius: 50px !important;
  215. color: #f8f8f8 !important;
  216. font-size: $global-font-size-18 !important;
  217. text-align: center !important;
  218. line-height: 40px !important;
  219. cursor: pointer !important;
  220. font-family: PingFangSC-Regular !important;
  221. background-color: $global-color-107 !important;
  222. }
  223. }
  224. .text {
  225. text-align: center;
  226. font-size: $global-font-size-18;
  227. span:last-child {
  228. color: $global-color-107;
  229. margin: 0 0 0 2px;
  230. cursor: default; /* 将鼠标样式更改为箭头 */
  231. }
  232. }
  233. .checks_box {
  234. display: flex;
  235. align-items: center;
  236. justify-content: center;
  237. .checks_inpt {
  238. margin: 0 5px 0 0;
  239. }
  240. .checks_text {
  241. cursor: default;
  242. span:last-child {
  243. color: #2374ff;
  244. }
  245. }
  246. }
  247. }
  248. }
  249. :deep(table) {
  250. border-collapse: collapse !important;
  251. width: 100% !important;
  252. text-align: center !important;
  253. }
  254. :deep(th) {
  255. border: 1px solid #ddd !important;
  256. padding: 8px !important;
  257. }
  258. :deep(td) {
  259. border: 1px solid #ddd !important;
  260. padding: 8px !important;
  261. }
  262. :deep(table tr:nth-child(even)) {
  263. background-color: #f2f2f2 !important;
  264. }
  265. :deep(table tr:hover) {
  266. background-color: #ddd !important;
  267. }
  268. }
  269. </style>