index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <view class="login-page">
  3. <nav-bar title="登录" bgColor="transparent" color="#fff" :showBack="false"></nav-bar>
  4. <!-- 顶部渐变装饰区 -->
  5. <view class="hero-bg">
  6. <view class="deco-circle c1"></view>
  7. <view class="deco-circle c2"></view>
  8. <view class="deco-circle c3"></view>
  9. <!-- 返回按钮 -->
  10. <view class="back-btn" @click="onClickLeft">
  11. <uni-icons type="left" size="22" color="#fff"></uni-icons>
  12. </view>
  13. <!-- Logo 区域 -->
  14. <view class="hero-content">
  15. <view class="logo-wrap">
  16. <uni-icons type="headphones" size="42" color="#fff"></uni-icons>
  17. </view>
  18. <text class="brand-name">好萌友</text>
  19. <text class="brand-desc">专业 · 安心 · 便捷</text>
  20. </view>
  21. </view>
  22. <!-- 表单白色卡片区 -->
  23. <view class="form-card">
  24. <text class="form-title">账号登录</text>
  25. <!-- 账号输入框 -->
  26. <view class="input-group">
  27. <view class="input-icon-wrap">
  28. <uni-icons type="person" size="18" color="#ffc837"></uni-icons>
  29. </view>
  30. <input class="custom-input" v-model="username" placeholder="请输入登录账号"
  31. placeholder-class="input-placeholder" />
  32. </view>
  33. <!-- 密码输入框 -->
  34. <view class="input-group">
  35. <view class="input-icon-wrap">
  36. <uni-icons type="locked" size="18" color="#ffc837"></uni-icons>
  37. </view>
  38. <input class="custom-input" v-model="password" type="password" placeholder="请输入密码"
  39. placeholder-class="input-placeholder" />
  40. </view>
  41. <!-- 提示信息 -->
  42. <view class="tip-row">
  43. <uni-icons type="info" size="13" color="#ffaa00"></uni-icons>
  44. <text>账号由后台创建,不支持自主注册</text>
  45. </view>
  46. <!-- 协议勾选 -->
  47. <view class="agreement-row">
  48. <checkbox-group @change="onCheckChange">
  49. <label class="agree-label">
  50. <checkbox :checked="checked" color="#ffc837" style="transform: scale(0.7);" />
  51. <text class="agree-text">我已阅读并同意</text>
  52. <text class="text-link" @click.stop="showAgreement(2)">《隐私政策》</text>
  53. <text class="agree-text">和</text>
  54. <text class="text-link" @click.stop="showAgreement(1)">《用户服务协议》</text>
  55. </label>
  56. </checkbox-group>
  57. </view>
  58. <!-- 登录按钮 -->
  59. <button class="login-btn" @click="onSubmit">安全登录</button>
  60. <!-- 注册入口 -->
  61. <view class="register-redirect-row">
  62. <text class="redirect-hint">还没有账号?</text>
  63. <text class="redirect-action" @click="goToRegister">立即注册</text>
  64. </view>
  65. </view>
  66. <!-- 底部装饰 -->
  67. <view class="footer-hint">
  68. <text>安全加密 · 保护您的账号信息</text>
  69. </view>
  70. </view>
  71. </template>
  72. <script setup>
  73. import { ref } from 'vue'
  74. import navBar from '@/components/nav-bar/index.vue'
  75. import { login } from '@/api/auth'
  76. import { getInfo } from '@/api/system/user'
  77. import { AgreementType } from '@/enums/agreementType'
  78. import { DEFAULT_HEADERS } from '@/utils/config'
  79. const username = ref('')
  80. const password = ref('')
  81. const checked = ref(false)
  82. const onClickLeft = () => uni.reLaunch({ url: '/pages/index/index' })
  83. const goToRegister = () => {
  84. uni.navigateTo({
  85. url: '/pages/login/register'
  86. })
  87. }
  88. const onCheckChange = () => {
  89. checked.value = !checked.value
  90. }
  91. const onSubmit = async () => {
  92. if (!username.value) {
  93. uni.showToast({ title: '请填写账号', icon: 'none' })
  94. return
  95. }
  96. if (!password.value) {
  97. uni.showToast({ title: '请填写密码', icon: 'none' })
  98. return
  99. }
  100. if (!checked.value) {
  101. uni.showToast({ title: '请先阅读并勾选协议', icon: 'none' })
  102. return
  103. }
  104. try {
  105. uni.showLoading({ title: '登录中...' })
  106. const res = await login({
  107. userSource: 0,
  108. username: username.value,
  109. password: password.value,
  110. clientId: DEFAULT_HEADERS.clientid,
  111. grantType: 'password',
  112. source: 1
  113. })
  114. if (res.access_token) {
  115. uni.setStorageSync('token', res.access_token)
  116. // 获取用户信息并存储 tenantId
  117. try {
  118. const userRes = await getInfo()
  119. if (userRes && userRes.user && userRes.user.tenantId) {
  120. uni.setStorageSync('tenantId', userRes.user.tenantId)
  121. }
  122. } catch (e) {
  123. console.error('获取用户信息失败', e)
  124. uni.showToast({ title: typeof e === 'string' ? e : '请求失败', icon: 'none' })
  125. }
  126. uni.showToast({ title: '登录成功', icon: 'success' })
  127. setTimeout(() => {
  128. uni.reLaunch({ url: '/pages/index/index' })
  129. }, 1000)
  130. } else {
  131. uni.showToast({ title: '登录异常:未获取到Token', icon: 'none' })
  132. }
  133. } catch (error) {
  134. console.error('Login error:', error)
  135. uni.showToast({ title: typeof error === 'string' ? error : '登录失败', icon: 'none' })
  136. } finally {
  137. uni.hideLoading()
  138. }
  139. }
  140. const showAgreement = (agreementId) => {
  141. const title = agreementId === 1 ? '用户服务协议' : '隐私政策'
  142. uni.navigateTo({
  143. url: `/pages/my/agreement/detail/index?id=${agreementId}&title=${encodeURIComponent(title)}`
  144. })
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .login-page {
  149. min-height: 100vh;
  150. background: #f2f3f7;
  151. display: flex;
  152. flex-direction: column;
  153. }
  154. :deep(.nav-bar) {
  155. position: absolute !important;
  156. }
  157. .hero-bg {
  158. background: linear-gradient(150deg, #ffd53f 0%, #ff9500 100%);
  159. padding: 0 40rpx 140rpx;
  160. position: relative;
  161. overflow: hidden;
  162. min-height: 560rpx;
  163. display: flex;
  164. flex-direction: column;
  165. justify-content: flex-end;
  166. }
  167. .deco-circle {
  168. position: absolute;
  169. border-radius: 50%;
  170. background: rgba(255, 255, 255, 0.12);
  171. }
  172. .c1 {
  173. width: 400rpx;
  174. height: 400rpx;
  175. top: -160rpx;
  176. right: -120rpx;
  177. }
  178. .c2 {
  179. width: 260rpx;
  180. height: 260rpx;
  181. top: 80rpx;
  182. left: -100rpx;
  183. }
  184. .c3 {
  185. width: 160rpx;
  186. height: 160rpx;
  187. bottom: 80rpx;
  188. right: 80rpx;
  189. }
  190. .back-btn {
  191. position: absolute;
  192. top: calc(var(--status-bar-height, 44px) + 20rpx);
  193. left: 32rpx;
  194. width: 76rpx;
  195. height: 76rpx;
  196. border-radius: 50%;
  197. background: rgba(255, 255, 255, 0.35);
  198. display: flex;
  199. align-items: center;
  200. justify-content: center;
  201. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
  202. z-index: 1000;
  203. }
  204. .hero-content {
  205. position: relative;
  206. z-index: 2;
  207. }
  208. .logo-wrap {
  209. width: 140rpx;
  210. height: 140rpx;
  211. background: rgba(255, 255, 255, 0.25);
  212. border-radius: 44rpx;
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. margin-bottom: 28rpx;
  217. }
  218. .brand-name {
  219. display: block;
  220. font-size: 52rpx;
  221. font-weight: 800;
  222. color: #fff;
  223. margin-bottom: 8rpx;
  224. }
  225. .brand-desc {
  226. display: block;
  227. font-size: 28rpx;
  228. color: rgba(255, 255, 255, 0.8);
  229. letter-spacing: 4rpx;
  230. }
  231. .form-card {
  232. background: #fff;
  233. border-radius: 56rpx 56rpx 0 0;
  234. margin-top: -60rpx;
  235. padding: 60rpx 48rpx 40rpx;
  236. flex: 1;
  237. position: relative;
  238. z-index: 10;
  239. }
  240. .form-title {
  241. display: block;
  242. font-size: 38rpx;
  243. font-weight: 700;
  244. color: #1a1a1a;
  245. margin-bottom: 48rpx;
  246. }
  247. .input-group {
  248. display: flex;
  249. align-items: center;
  250. background: #f8f8f8;
  251. border-radius: 28rpx;
  252. padding: 8rpx 24rpx;
  253. margin-bottom: 28rpx;
  254. border: 3rpx solid transparent;
  255. }
  256. .input-icon-wrap {
  257. margin-right: 16rpx;
  258. flex-shrink: 0;
  259. }
  260. .custom-input {
  261. flex: 1;
  262. height: 88rpx;
  263. font-size: 30rpx;
  264. color: #222;
  265. background: transparent;
  266. }
  267. .input-placeholder {
  268. color: #c0c0c0;
  269. }
  270. .tip-row {
  271. display: flex;
  272. align-items: center;
  273. gap: 10rpx;
  274. font-size: 24rpx;
  275. color: #aaa;
  276. padding: 8rpx 8rpx 24rpx;
  277. }
  278. .agreement-row {
  279. margin-bottom: 48rpx;
  280. padding: 0 4rpx;
  281. }
  282. .agree-label {
  283. display: flex;
  284. align-items: center;
  285. flex-wrap: wrap;
  286. }
  287. .agree-text {
  288. font-size: 24rpx;
  289. color: #999;
  290. }
  291. .text-link {
  292. font-size: 24rpx;
  293. color: #ff9500;
  294. }
  295. .login-btn {
  296. width: 100%;
  297. height: 104rpx;
  298. font-size: 34rpx;
  299. font-weight: 700;
  300. color: #fff;
  301. background: linear-gradient(90deg, #ffd53f, #ff9500);
  302. border: none;
  303. border-radius: 52rpx;
  304. letter-spacing: 4rpx;
  305. &::after {
  306. border: none;
  307. }
  308. }
  309. .footer-hint {
  310. text-align: center;
  311. font-size: 22rpx;
  312. color: #bbb;
  313. padding: 32rpx 0 60rpx;
  314. background: #fff;
  315. }
  316. .register-redirect-row {
  317. display: flex;
  318. justify-content: center;
  319. align-items: center;
  320. margin-top: 36rpx;
  321. font-size: 26rpx;
  322. }
  323. .redirect-hint {
  324. color: #999;
  325. }
  326. .redirect-action {
  327. color: #ff9500;
  328. font-weight: bold;
  329. margin-left: 12rpx;
  330. text-decoration: underline;
  331. }
  332. </style>