index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <view class="login-page">
  3. <nav-bar title="登录" bgColor="transparent" color="#fff"></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="20" 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(4)">《托运协议》</text>
  55. </label>
  56. </checkbox-group>
  57. </view>
  58. <!-- 登录按钮 -->
  59. <button class="login-btn" @click="onSubmit">安全登录</button>
  60. </view>
  61. <!-- 底部装饰 -->
  62. <view class="footer-hint">
  63. <text>安全加密 · 保护您的账号信息</text>
  64. </view>
  65. <!-- 隐私政策/托运协议弹窗 -->
  66. <policy-dialog v-model:visible="dialogVisible" :title="dialogTitle" :content="dialogContent"></policy-dialog>
  67. </view>
  68. </template>
  69. <script setup>
  70. import { ref } from 'vue'
  71. import navBar from '@/components/nav-bar/index.vue'
  72. import policyDialog from '@/components/policy-dialog/index.vue'
  73. import { login } from '@/api/auth'
  74. import { getAgreement } from '@/api/system/agreement'
  75. import { AgreementType } from '@/enums/agreementType'
  76. import { DEFAULT_HEADERS } from '@/utils/config'
  77. const username = ref('')
  78. const password = ref('')
  79. const checked = ref(false)
  80. const dialogVisible = ref(false)
  81. const dialogTitle = ref('')
  82. const dialogContent = ref('')
  83. const onClickLeft = () => uni.navigateBack()
  84. const onCheckChange = () => {
  85. checked.value = !checked.value
  86. }
  87. const onSubmit = async () => {
  88. if (!username.value) {
  89. uni.showToast({ title: '请填写账号', icon: 'none' })
  90. return
  91. }
  92. if (!password.value) {
  93. uni.showToast({ title: '请填写密码', icon: 'none' })
  94. return
  95. }
  96. if (!checked.value) {
  97. uni.showToast({ title: '请先阅读并勾选协议', icon: 'none' })
  98. return
  99. }
  100. try {
  101. uni.showLoading({ title: '登录中...' })
  102. const res = await login({
  103. userSource: 0,
  104. username: username.value,
  105. password: password.value,
  106. clientId: DEFAULT_HEADERS.clientid,
  107. grantType: 'password',
  108. source: 1
  109. })
  110. if (res.access_token) {
  111. uni.setStorageSync('token', res.access_token)
  112. uni.showToast({ title: '登录成功', icon: 'success' })
  113. setTimeout(() => {
  114. uni.reLaunch({ url: '/pages/index/index' })
  115. }, 1000)
  116. } else {
  117. uni.showToast({ title: '登录异常:未获取到Token', icon: 'none' })
  118. }
  119. } catch (error) {
  120. console.error('Login error:', error)
  121. // 注意这里的提示也可以通过request.js自带去提示,这里静默或者输出
  122. } finally {
  123. uni.hideLoading()
  124. }
  125. }
  126. const showAgreement = async (agreementId) => {
  127. try {
  128. uni.showLoading({ title: '加载中...' })
  129. const res = await getAgreement(agreementId)
  130. if (res && res.title) {
  131. dialogTitle.value = res.title || '协议详情'
  132. dialogContent.value = res.content || '暂无内容'
  133. dialogVisible.value = true
  134. } else {
  135. console.warn('接口返回数据格式异常:', res)
  136. uni.showToast({ title: '数据格式异常', icon: 'none' })
  137. }
  138. } catch (error) {
  139. console.error('获取协议失败:', error)
  140. uni.showToast({ title: '加载失败,请稍后重试', icon: 'none' })
  141. } finally {
  142. uni.hideLoading()
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .login-page {
  148. min-height: 100vh;
  149. background: #f2f3f7;
  150. display: flex;
  151. flex-direction: column;
  152. }
  153. .hero-bg {
  154. background: linear-gradient(150deg, #ffd53f 0%, #ff9500 100%);
  155. padding: 0 40rpx 140rpx;
  156. position: relative;
  157. overflow: hidden;
  158. min-height: 560rpx;
  159. display: flex;
  160. flex-direction: column;
  161. justify-content: flex-end;
  162. margin-top: calc(-44px - var(--status-bar-height, 44px));
  163. }
  164. .deco-circle {
  165. position: absolute;
  166. border-radius: 50%;
  167. background: rgba(255, 255, 255, 0.12);
  168. }
  169. .c1 {
  170. width: 400rpx;
  171. height: 400rpx;
  172. top: -160rpx;
  173. right: -120rpx;
  174. }
  175. .c2 {
  176. width: 260rpx;
  177. height: 260rpx;
  178. top: 80rpx;
  179. left: -100rpx;
  180. }
  181. .c3 {
  182. width: 160rpx;
  183. height: 160rpx;
  184. bottom: 80rpx;
  185. right: 80rpx;
  186. }
  187. .back-btn {
  188. position: absolute;
  189. top: calc(var(--status-bar-height, 44px) + 20rpx);
  190. left: 32rpx;
  191. width: 72rpx;
  192. height: 72rpx;
  193. border-radius: 50%;
  194. background: rgba(255, 255, 255, 0.25);
  195. display: flex;
  196. align-items: center;
  197. justify-content: center;
  198. }
  199. .hero-content {
  200. position: relative;
  201. z-index: 2;
  202. }
  203. .logo-wrap {
  204. width: 140rpx;
  205. height: 140rpx;
  206. background: rgba(255, 255, 255, 0.25);
  207. border-radius: 44rpx;
  208. display: flex;
  209. align-items: center;
  210. justify-content: center;
  211. margin-bottom: 28rpx;
  212. }
  213. .brand-name {
  214. display: block;
  215. font-size: 52rpx;
  216. font-weight: 800;
  217. color: #fff;
  218. margin-bottom: 8rpx;
  219. }
  220. .brand-desc {
  221. display: block;
  222. font-size: 28rpx;
  223. color: rgba(255, 255, 255, 0.8);
  224. letter-spacing: 4rpx;
  225. }
  226. .form-card {
  227. background: #fff;
  228. border-radius: 56rpx 56rpx 0 0;
  229. margin-top: -60rpx;
  230. padding: 60rpx 48rpx 40rpx;
  231. flex: 1;
  232. position: relative;
  233. z-index: 10;
  234. }
  235. .form-title {
  236. display: block;
  237. font-size: 38rpx;
  238. font-weight: 700;
  239. color: #1a1a1a;
  240. margin-bottom: 48rpx;
  241. }
  242. .input-group {
  243. display: flex;
  244. align-items: center;
  245. background: #f8f8f8;
  246. border-radius: 28rpx;
  247. padding: 8rpx 24rpx;
  248. margin-bottom: 28rpx;
  249. border: 3rpx solid transparent;
  250. }
  251. .input-icon-wrap {
  252. margin-right: 16rpx;
  253. flex-shrink: 0;
  254. }
  255. .custom-input {
  256. flex: 1;
  257. height: 88rpx;
  258. font-size: 30rpx;
  259. color: #222;
  260. background: transparent;
  261. }
  262. .input-placeholder {
  263. color: #c0c0c0;
  264. }
  265. .tip-row {
  266. display: flex;
  267. align-items: center;
  268. gap: 10rpx;
  269. font-size: 24rpx;
  270. color: #aaa;
  271. padding: 8rpx 8rpx 24rpx;
  272. }
  273. .agreement-row {
  274. margin-bottom: 48rpx;
  275. padding: 0 4rpx;
  276. }
  277. .agree-label {
  278. display: flex;
  279. align-items: center;
  280. flex-wrap: wrap;
  281. }
  282. .agree-text {
  283. font-size: 24rpx;
  284. color: #999;
  285. }
  286. .text-link {
  287. font-size: 24rpx;
  288. color: #ff9500;
  289. }
  290. .login-btn {
  291. width: 100%;
  292. height: 104rpx;
  293. font-size: 34rpx;
  294. font-weight: 700;
  295. color: #333;
  296. background: linear-gradient(90deg, #ffd53f, #ff9500);
  297. border: none;
  298. border-radius: 52rpx;
  299. letter-spacing: 4rpx;
  300. }
  301. .footer-hint {
  302. text-align: center;
  303. font-size: 22rpx;
  304. color: #bbb;
  305. padding: 32rpx 0 60rpx;
  306. background: #fff;
  307. }
  308. </style>