login.uvue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <template>
  2. <view class="page-container">
  3. <view class="close-btn" @click="goBack">
  4. <uni-icons type="closeempty" size="24" color="#333">
  5. </uni-icons>
  6. </view>
  7. <view class="header-section">
  8. <text class="hello-text">
  9. Hello!
  10. </text>
  11. <text class="welcome-text">
  12. 欢迎来到小丁到家
  13. </text>
  14. <image src="/static/logo-massage.png" class="logo-img" mode="aspectFit">
  15. </image>
  16. </view>
  17. <view class="form-section">
  18. <view class="input-box">
  19. <input class="input-field" type="number" placeholder="请输入手机号码" v-model="phone" maxlength="11" />
  20. </view>
  21. <view class="input-box row-between">
  22. <input class="input-field" type="number" placeholder="请输入验证码" v-model="code" maxlength="6" />
  23. <text class="code-btn" :class="{ disabled: !canSend }" @click="sendCode">
  24. {{ codeText }}
  25. </text>
  26. </view>
  27. <view class="login-btn" :class="{ disabled: !canLogin }" @click="doLogin">
  28. 登录
  29. </view>
  30. <view class="agree-row row-start">
  31. <checkbox :checked="isAgree" @change="onAgreeChange" style="transform: scale(0.8);" />
  32. <view class="agree-content">
  33. <text class="agree-text">
  34. 我已阅读并同意
  35. <text class="link-text">
  36. 《用户协议》
  37. </text>
  38. <text class="link-text">
  39. 《隐私政策》
  40. </text>
  41. <text class="link-text">
  42. 《上门按摩服务行业平台公约》
  43. </text>
  44. ,未注册的手机号将自动创建小丁到家账号
  45. </text>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="footer-section">
  50. <view class="divider-row row-center">
  51. <view class="line">
  52. </view>
  53. <text class="divider-text">
  54. 其他登录方式
  55. </text>
  56. <view class="line">
  57. </view>
  58. </view>
  59. <view class="methods-row row-center">
  60. <view class="method-item column-center" @click="oneKeyNav">
  61. <view class="icon-box blue-bg">
  62. <uni-icons type="checkmark" size="20" color="#fff">
  63. </uni-icons>
  64. </view>
  65. <text class="method-name">
  66. 一键登录
  67. </text>
  68. </view>
  69. <view class="method-item column-center" @click="wechatLogin">
  70. <view class="icon-box green-bg">
  71. <uni-icons type="weixin" size="20" color="#fff"></uni-icons>
  72. </view>
  73. <text class="method-name">
  74. 微信登录
  75. </text>
  76. </view>
  77. </view>
  78. </view>
  79. <view v-if="showModal" class="modal-mask" @click="showModal=false">
  80. <view class="modal-box" @click.stop>
  81. <text class="modal-title">
  82. 服务协议及隐私政策
  83. </text>
  84. <scroll-view scroll-y class="modal-scroll">
  85. <text class="modal-welcome">
  86. 欢迎您使用小丁到家!
  87. </text>
  88. <text class="modal-desc">
  89. 请你务必审慎阅读、并充分理解
  90. <text class="modal-link">
  91. 《用户协议》
  92. </text>
  93. <text class="modal-link">
  94. 《隐私政策》
  95. </text>
  96. ,协议内容包括但不限于:
  97. </text>
  98. <text class="modal-list">
  99. 1、在您使用软件及服务的过程中,向您提供相关基本功能,我们将根据合法、正当、必要的原则,收集或使用必要的个人信息;
  100. </text>
  101. <text class="modal-list">
  102. 2、基于您的授权,我们可能会获取您的地理位置、相册、相机等相关软件权限;
  103. </text>
  104. <text class="modal-list">
  105. 3、我们会采取符合标准的技术措施和数据安全措施来保护您的个人信息安全;
  106. </text>
  107. <text class="modal-list">
  108. 4、您可以查询,更正,管理您的个人信息,我们也提供账户注销的渠道;
  109. </text>
  110. <text class="modal-footer">
  111. 如您同意以上协议内容,请点击“同意”开始使用我们的产品和服务,我们依法尽全力保护您的个人信息。
  112. </text>
  113. </scroll-view>
  114. <view class="modal-btns row-between">
  115. <text class="modal-btn reject" @click="rejectAgreement">
  116. 拒绝并退出
  117. </text>
  118. <text class="modal-btn agree" @click="agreeAgreement">
  119. 同意
  120. </text>
  121. </view>
  122. </view>
  123. </view>
  124. </view>
  125. </template>
  126. <script setup lang="uts">
  127. import { ref, computed } from 'vue';
  128. const phone = ref<string>('');
  129. const code = ref<string>('');
  130. const isAgree = ref<boolean>(false);
  131. const showModal = ref<boolean>(false);
  132. const countdown = ref<number>(0);
  133. // 定义定时器变量
  134. let timer : number | null = null;
  135. const canSend = computed(() => phone.value.length === 11 && countdown.value === 0);
  136. const canLogin = computed(() => phone.value.length === 11 && code.value.length === 6 && isAgree.value);
  137. const codeText = computed(() => countdown.value > 0 ? `${countdown.value}s 后重试` : '获取验证码');
  138. const goBack = () => uni.navigateBack();
  139. const oneKeyNav = () => uni.navigateTo({ url: '/pages/login/login-one-key' });
  140. const wechatLogin = () => uni.showToast({ title: '微信登录开发中', icon: 'none' });
  141. const sendCode = () => {
  142. if (!canSend.value) return;
  143. const currentTimer = timer;
  144. if (currentTimer !== null) {
  145. clearInterval(currentTimer);
  146. }
  147. timer = null;
  148. countdown.value = 60;
  149. uni.showToast({ title: '验证码已发送', icon: 'success' });
  150. timer = setInterval(() => {
  151. countdown.value--;
  152. if (countdown.value <= 0) {
  153. const t = timer;
  154. if (t !== null) {
  155. clearInterval(t);
  156. }
  157. timer = null;
  158. countdown.value = 0;
  159. }
  160. }, 1000);
  161. };
  162. const onAgreeChange = (e : any) => {
  163. // UTS 中 any 类型必须 as 成具体类型再访问属性
  164. const evt = e as UTSJSONObject;
  165. if (evt != null) {
  166. const detail = evt["detail"] as UTSJSONObject | null;
  167. if (detail != null) {
  168. const value = detail["value"] as boolean | null;
  169. isAgree.value = (value != null) && value;
  170. return;
  171. }
  172. }
  173. isAgree.value = false;
  174. };
  175. const doLogin = () => {
  176. if (!canLogin.value) {
  177. uni.showToast({ title: isAgree.value ? '请填写完整信息' : '请先同意协议', icon: 'none' });
  178. return;
  179. }
  180. uni.showLoading({ title: '登录中...' });
  181. setTimeout(() => {
  182. uni.hideLoading();
  183. uni.showToast({ title: '登录成功', icon: 'success' });
  184. }, 1500);
  185. };
  186. const rejectAgreement = () => {
  187. showModal.value = false;
  188. uni.showToast({ title: '您拒绝了协议', icon: 'none' });
  189. };
  190. const agreeAgreement = () => {
  191. showModal.value = false;
  192. isAgree.value = true;
  193. uni.showToast({ title: '已同意协议', icon: 'success' });
  194. };
  195. </script>
  196. <style>
  197. .page-container {
  198. background: linear-gradient(180deg, #e0f7fa 0%, #fff8e1 100%);
  199. height: 100%;
  200. padding: 40rpx 30rpx;
  201. box-sizing: border-box;
  202. }
  203. .close-btn {
  204. position: absolute;
  205. top: 40rpx;
  206. right: 30rpx;
  207. z-index: 10;
  208. }
  209. .header-section {
  210. align-items: center;
  211. margin-bottom: 60rpx;
  212. }
  213. .hello-text {
  214. font-size: 48rpx;
  215. font-weight: bold;
  216. color: #333;
  217. margin-bottom: 10rpx;
  218. }
  219. .welcome-text {
  220. font-size: 32rpx;
  221. color: #666;
  222. margin-bottom: 30rpx;
  223. }
  224. .logo-img {
  225. width: 300rpx;
  226. height: 300rpx;
  227. border-radius: 150rpx;
  228. background-color: rgba(255, 255, 255, 0.3);
  229. }
  230. .form-section {
  231. margin-bottom: 60rpx;
  232. }
  233. .input-box {
  234. background-color: #ffffff;
  235. border-radius: 30rpx;
  236. padding: 20rpx 30rpx;
  237. margin-bottom: 30rpx;
  238. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  239. }
  240. .input-field {
  241. flex: 1;
  242. font-size: 28rpx;
  243. color: #333;
  244. }
  245. .code-btn {
  246. font-size: 26rpx;
  247. color: #ffc107;
  248. font-weight: bold;
  249. white-space: nowrap;
  250. }
  251. .code-btn.disabled {
  252. color: #ccc;
  253. }
  254. .login-btn {
  255. background: linear-gradient(90deg, #ffc107, #ffca2c);
  256. color: #ffffff;
  257. font-size: 32rpx;
  258. font-weight: bold;
  259. text-align: center;
  260. padding: 24rpx 0;
  261. border-radius: 30rpx;
  262. margin-bottom: 30rpx;
  263. box-shadow: 0 4rpx 12rpx rgba(255, 193, 7, 0.3);
  264. }
  265. .login-btn.disabled {
  266. background: #ddd;
  267. color: #999;
  268. box-shadow: none;
  269. }
  270. .agree-row {
  271. align-items: flex-start;
  272. }
  273. .agree-content {
  274. flex: 1;
  275. margin-left: 10rpx;
  276. }
  277. .agree-text {
  278. font-size: 24rpx;
  279. color: #999;
  280. line-height: 1.6;
  281. }
  282. .link-text {
  283. color: #00b894;
  284. border-bottom: 1rpx solid #00b894;
  285. }
  286. .footer-section {
  287. margin-top: auto;
  288. }
  289. .divider-row {
  290. margin-bottom: 40rpx;
  291. align-items: center;
  292. }
  293. .line {
  294. flex: 1;
  295. height: 1rpx;
  296. background-color: #ddd;
  297. }
  298. .divider-text {
  299. font-size: 26rpx;
  300. color: #999;
  301. margin: 0 20rpx;
  302. }
  303. .methods-row {
  304. justify-content: center;
  305. margin-bottom: 40rpx;
  306. }
  307. .method-item {
  308. margin-right: 60rpx;
  309. align-items: center;
  310. }
  311. .method-item:last-child {
  312. margin-right: 0;
  313. }
  314. .icon-box {
  315. width: 80rpx;
  316. height: 80rpx;
  317. border-radius: 40rpx;
  318. justify-content: center;
  319. align-items: center;
  320. margin-bottom: 15rpx;
  321. }
  322. .blue-bg {
  323. background: linear-gradient(135deg, #4a90e2, #67b26f);
  324. }
  325. .green-bg {
  326. background: linear-gradient(135deg, #00b894, #00cec9);
  327. }
  328. .method-name {
  329. font-size: 26rpx;
  330. color: #666;
  331. }
  332. .modal-mask {
  333. position: fixed;
  334. top: 0;
  335. left: 0;
  336. right: 0;
  337. bottom: 0;
  338. background-color: rgba(0, 0, 0, 0.5);
  339. justify-content: center;
  340. align-items: center;
  341. z-index: 100;
  342. }
  343. .modal-box {
  344. background-color: #ffffff;
  345. border-radius: 20rpx;
  346. padding: 40rpx 30rpx;
  347. width: 600rpx;
  348. max-height: 800rpx;
  349. flex-direction: column;
  350. }
  351. .modal-title {
  352. font-size: 36rpx;
  353. font-weight: bold;
  354. color: #333;
  355. text-align: center;
  356. margin-bottom: 20rpx;
  357. }
  358. .modal-scroll {
  359. flex: 1;
  360. margin-bottom: 20rpx;
  361. }
  362. .modal-welcome {
  363. font-size: 28rpx;
  364. color: #333;
  365. margin-bottom: 15rpx;
  366. }
  367. .modal-desc {
  368. font-size: 26rpx;
  369. color: #666;
  370. line-height: 1.6;
  371. margin-bottom: 15rpx;
  372. }
  373. .modal-link {
  374. color: #00b894;
  375. border-bottom: 1rpx solid #00b894;
  376. }
  377. .modal-list {
  378. font-size: 26rpx;
  379. color: #666;
  380. line-height: 1.6;
  381. margin-bottom: 10rpx;
  382. }
  383. .modal-footer {
  384. font-size: 26rpx;
  385. color: #666;
  386. line-height: 1.6;
  387. margin-bottom: 10rpx;
  388. }
  389. .modal-btns {
  390. border-top: 1rpx solid #eee;
  391. padding-top: 20rpx;
  392. }
  393. .modal-btn {
  394. flex: 1;
  395. text-align: center;
  396. font-size: 28rpx;
  397. font-weight: bold;
  398. padding: 15rpx 0;
  399. }
  400. .modal-btn.reject {
  401. color: #999;
  402. margin-right: 20rpx;
  403. }
  404. .modal-btn.agree {
  405. color: #00b894;
  406. }
  407. .row-between {
  408. flex-direction: row;
  409. justify-content: space-between;
  410. align-items: center;
  411. }
  412. .row-start {
  413. flex-direction: row;
  414. align-items: flex-start;
  415. }
  416. .row-center {
  417. flex-direction: row;
  418. justify-content: center;
  419. align-items: center;
  420. }
  421. .column-center {
  422. flex-direction: column;
  423. justify-content: center;
  424. align-items: center;
  425. }
  426. </style>