login.uvue.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import { ref, computed } from 'vue';
  2. const __sfc__ = defineComponent({
  3. __name: 'login',
  4. setup(__props) {
  5. const __ins = getCurrentInstance()!;
  6. const _ctx = __ins.proxy as InstanceType<typeof __sfc__>;
  7. const _cache = __ins.renderCache;
  8. const phone = ref<string>('');
  9. const code = ref<string>('');
  10. const isAgree = ref<boolean>(false);
  11. const showModal = ref<boolean>(false);
  12. const countdown = ref<number>(0);
  13. // 定义定时器变量
  14. let timer : number | null = null;
  15. const canSend = computed(() => phone.value.length === 11 && countdown.value === 0);
  16. const canLogin = computed(() => phone.value.length === 11 && code.value.length === 6 && isAgree.value);
  17. const codeText = computed(() => countdown.value > 0 ? `${countdown.value}s 后重试` : '获取验证码');
  18. const goBack = () => uni.navigateBack();
  19. const oneKeyNav = () => uni.navigateTo({ url: '/pages/login/login-one-key' });
  20. const wechatLogin = () => uni.showToast({ title: '微信登录开发中', icon: 'none' });
  21. const sendCode = () => {
  22. if (!canSend.value) return;
  23. // ✅ 修复核心:先取值到局部常量,再操作
  24. const currentTimer = timer;
  25. if (currentTimer !== null) {
  26. clearInterval(currentTimer);
  27. }
  28. timer = null;
  29. countdown.value = 60;
  30. uni.showToast({ title: '验证码已发送', icon: 'success' });
  31. timer = setInterval(() => {
  32. countdown.value--;
  33. if (countdown.value <= 0) {
  34. // ✅ 同样在闭包内先取局部常量
  35. const t = timer;
  36. if (t !== null) {
  37. clearInterval(t);
  38. }
  39. timer = null;
  40. countdown.value = 0;
  41. }
  42. }, 1000);
  43. };
  44. const onAgreeChange = (e : any) => {
  45. // UTS 中 any 类型必须 as 成具体类型再访问属性
  46. const evt = e as UTSJSONObject;
  47. if (evt != null) {
  48. const detail = evt["detail"] as UTSJSONObject | null;
  49. if (detail != null) {
  50. const value = detail["value"] as Boolean | null;
  51. isAgree.value = (value != null) && value;
  52. return;
  53. }
  54. }
  55. isAgree.value = false;
  56. };
  57. const doLogin = () => {
  58. if (!canLogin.value) {
  59. uni.showToast({ title: isAgree.value ? '请填写完整信息' : '请先同意协议', icon: 'none' });
  60. return;
  61. }
  62. uni.showLoading({ title: '登录中...' });
  63. setTimeout(() => {
  64. uni.hideLoading();
  65. uni.showToast({ title: '登录成功', icon: 'success' });
  66. }, 1500);
  67. };
  68. const rejectAgreement = () => {
  69. showModal.value = false;
  70. uni.showToast({ title: '您拒绝了协议', icon: 'none' });
  71. };
  72. const agreeAgreement = () => {
  73. showModal.value = false;
  74. isAgree.value = true;
  75. uni.showToast({ title: '已同意协议', icon: 'success' });
  76. };
  77. return (): any | null => {
  78. const _component_uni_icons = resolveComponent("uni-icons")
  79. const _component_checkbox = resolveComponent("checkbox")
  80. return _cE("view", _uM({ class: "page-container" }), [
  81. _cE("view", _uM({
  82. class: "close-btn",
  83. onClick: goBack
  84. }), [
  85. _cV(_component_uni_icons, _uM({
  86. type: "closeempty",
  87. size: "24",
  88. color: "#333"
  89. }))
  90. ]),
  91. _cE("view", _uM({ class: "header-section" }), [
  92. _cE("text", _uM({ class: "hello-text" }), " Hello! "),
  93. _cE("text", _uM({ class: "welcome-text" }), " 欢迎来到小丁到家 "),
  94. _cE("image", _uM({
  95. src: "/static/logo-massage.png",
  96. class: "logo-img",
  97. mode: "aspectFit"
  98. }))
  99. ]),
  100. _cE("view", _uM({ class: "form-section" }), [
  101. _cE("view", _uM({ class: "input-box" }), [
  102. _cE("input", _uM({
  103. class: "input-field",
  104. type: "number",
  105. placeholder: "请输入手机号码",
  106. modelValue: phone.value,
  107. onInput: ($event: UniInputEvent) => {(phone).value = $event.detail.value},
  108. maxlength: "11"
  109. }), null, 40 /* PROPS, NEED_HYDRATION */, ["modelValue", "onInput"])
  110. ]),
  111. _cE("view", _uM({ class: "input-box row-between" }), [
  112. _cE("input", _uM({
  113. class: "input-field",
  114. type: "number",
  115. placeholder: "请输入验证码",
  116. modelValue: code.value,
  117. onInput: ($event: UniInputEvent) => {(code).value = $event.detail.value},
  118. maxlength: "6"
  119. }), null, 40 /* PROPS, NEED_HYDRATION */, ["modelValue", "onInput"]),
  120. _cE("text", _uM({
  121. class: _nC(["code-btn", _uM({ disabled: !canSend.value })]),
  122. onClick: sendCode
  123. }), _tD(codeText.value), 3 /* TEXT, CLASS */)
  124. ]),
  125. _cE("view", _uM({
  126. class: _nC(["login-btn", _uM({ disabled: !canLogin.value })]),
  127. onClick: doLogin
  128. }), " 登录 ", 2 /* CLASS */),
  129. _cE("view", _uM({ class: "agree-row row-start" }), [
  130. _cV(_component_checkbox, _uM({
  131. checked: isAgree.value,
  132. onChange: onAgreeChange,
  133. style: _nS(_uM({"transform":"scale(0.8)"}))
  134. }), null, 8 /* PROPS */, ["checked", "style"]),
  135. _cE("view", _uM({ class: "agree-content" }), [
  136. _cE("text", _uM({ class: "agree-text" }), [
  137. " 我已阅读并同意 ",
  138. _cE("text", _uM({ class: "link-text" }), " 《用户协议》 "),
  139. _cE("text", _uM({ class: "link-text" }), " 《隐私政策》 "),
  140. _cE("text", _uM({ class: "link-text" }), " 《上门按摩服务行业平台公约》 "),
  141. " ,未注册的手机号将自动创建小丁到家账号 "
  142. ])
  143. ])
  144. ])
  145. ]),
  146. _cE("view", _uM({ class: "footer-section" }), [
  147. _cE("view", _uM({ class: "divider-row row-center" }), [
  148. _cE("view", _uM({ class: "line" })),
  149. _cE("text", _uM({ class: "divider-text" }), " 其他登录方式 "),
  150. _cE("view", _uM({ class: "line" }))
  151. ]),
  152. _cE("view", _uM({ class: "methods-row row-center" }), [
  153. _cE("view", _uM({
  154. class: "method-item column-center",
  155. onClick: oneKeyNav
  156. }), [
  157. _cE("view", _uM({ class: "icon-box blue-bg" }), [
  158. _cV(_component_uni_icons, _uM({
  159. type: "checkmark",
  160. size: "20",
  161. color: "#fff"
  162. }))
  163. ]),
  164. _cE("text", _uM({ class: "method-name" }), " 一键登录 ")
  165. ]),
  166. _cE("view", _uM({
  167. class: "method-item column-center",
  168. onClick: wechatLogin
  169. }), [
  170. _cE("view", _uM({ class: "icon-box green-bg" }), [
  171. _cV(_component_uni_icons, _uM({
  172. type: "weixin",
  173. size: "20",
  174. color: "#fff"
  175. }))
  176. ]),
  177. _cE("text", _uM({ class: "method-name" }), " 微信登录 ")
  178. ])
  179. ])
  180. ]),
  181. isTrue(showModal.value)
  182. ? _cE("view", _uM({
  183. key: 0,
  184. class: "modal-mask",
  185. onClick: () => {showModal.value=false}
  186. }), [
  187. _cE("view", _uM({
  188. class: "modal-box",
  189. onClick: withModifiers(() => {}, ["stop"])
  190. }), [
  191. _cE("text", _uM({ class: "modal-title" }), " 服务协议及隐私政策 "),
  192. _cE("scroll-view", _uM({
  193. "scroll-y": "",
  194. class: "modal-scroll"
  195. }), [
  196. _cE("text", _uM({ class: "modal-welcome" }), " 欢迎您使用小丁到家! "),
  197. _cE("text", _uM({ class: "modal-desc" }), [
  198. " 请你务必审慎阅读、并充分理解 ",
  199. _cE("text", _uM({ class: "modal-link" }), " 《用户协议》 "),
  200. " 和 ",
  201. _cE("text", _uM({ class: "modal-link" }), " 《隐私政策》 "),
  202. " ,协议内容包括但不限于: "
  203. ]),
  204. _cE("text", _uM({ class: "modal-list" }), " 1、在您使用软件及服务的过程中,向您提供相关基本功能,我们将根据合法、正当、必要的原则,收集或使用必要的个人信息; "),
  205. _cE("text", _uM({ class: "modal-list" }), " 2、基于您的授权,我们可能会获取您的地理位置、相册、相机等相关软件权限; "),
  206. _cE("text", _uM({ class: "modal-list" }), " 3、我们会采取符合标准的技术措施和数据安全措施来保护您的个人信息安全; "),
  207. _cE("text", _uM({ class: "modal-list" }), " 4、您可以查询,更正,管理您的个人信息,我们也提供账户注销的渠道; "),
  208. _cE("text", _uM({ class: "modal-footer" }), " 如您同意以上协议内容,请点击“同意”开始使用我们的产品和服务,我们依法尽全力保护您的个人信息。 ")
  209. ]),
  210. _cE("view", _uM({ class: "modal-btns row-between" }), [
  211. _cE("text", _uM({
  212. class: "modal-btn reject",
  213. onClick: rejectAgreement
  214. }), " 拒绝并退出 "),
  215. _cE("text", _uM({
  216. class: "modal-btn agree",
  217. onClick: agreeAgreement
  218. }), " 同意 ")
  219. ])
  220. ], 8 /* PROPS */, ["onClick"])
  221. ], 8 /* PROPS */, ["onClick"])
  222. : _cC("v-if", true)
  223. ])
  224. }
  225. }
  226. })
  227. export default __sfc__
  228. const GenPagesLoginLoginStyles = [_uM([["page-container", _pS(_uM([["backgroundImage", "linear-gradient(180deg, #e0f7fa 0%, #fff8e1 100%)"], ["backgroundColor", "rgba(0,0,0,0)"], ["height", "100%"], ["paddingTop", "40rpx"], ["paddingRight", "30rpx"], ["paddingBottom", "40rpx"], ["paddingLeft", "30rpx"], ["boxSizing", "border-box"]]))], ["close-btn", _pS(_uM([["position", "absolute"], ["top", "40rpx"], ["right", "30rpx"], ["zIndex", 10]]))], ["header-section", _pS(_uM([["alignItems", "center"], ["marginBottom", "60rpx"]]))], ["hello-text", _pS(_uM([["fontSize", "48rpx"], ["fontWeight", "bold"], ["color", "#333333"], ["marginBottom", "10rpx"]]))], ["welcome-text", _pS(_uM([["fontSize", "32rpx"], ["color", "#666666"], ["marginBottom", "30rpx"]]))], ["logo-img", _pS(_uM([["width", "300rpx"], ["height", "300rpx"], ["borderTopLeftRadius", "150rpx"], ["borderTopRightRadius", "150rpx"], ["borderBottomRightRadius", "150rpx"], ["borderBottomLeftRadius", "150rpx"], ["backgroundColor", "rgba(255,255,255,0.3)"]]))], ["form-section", _pS(_uM([["marginBottom", "60rpx"]]))], ["input-box", _pS(_uM([["backgroundColor", "#ffffff"], ["borderTopLeftRadius", "30rpx"], ["borderTopRightRadius", "30rpx"], ["borderBottomRightRadius", "30rpx"], ["borderBottomLeftRadius", "30rpx"], ["paddingTop", "20rpx"], ["paddingRight", "30rpx"], ["paddingBottom", "20rpx"], ["paddingLeft", "30rpx"], ["marginBottom", "30rpx"], ["boxShadow", "0 2rpx 8rpx rgba(0, 0, 0, 0.05)"]]))], ["input-field", _pS(_uM([["flexGrow", 1], ["flexShrink", 1], ["flexBasis", "0%"], ["fontSize", "28rpx"], ["color", "#333333"]]))], ["code-btn", _uM([["", _uM([["fontSize", "26rpx"], ["color", "#ffc107"], ["fontWeight", "bold"], ["whiteSpace", "nowrap"]])], [".disabled", _uM([["color", "#cccccc"]])]])], ["login-btn", _uM([["", _uM([["backgroundImage", "linear-gradient(90deg, #ffc107, #ffca2c)"], ["backgroundColor", "rgba(0,0,0,0)"], ["color", "#ffffff"], ["fontSize", "32rpx"], ["fontWeight", "bold"], ["textAlign", "center"], ["paddingTop", "24rpx"], ["paddingRight", 0], ["paddingBottom", "24rpx"], ["paddingLeft", 0], ["borderTopLeftRadius", "30rpx"], ["borderTopRightRadius", "30rpx"], ["borderBottomRightRadius", "30rpx"], ["borderBottomLeftRadius", "30rpx"], ["marginBottom", "30rpx"], ["boxShadow", "0 4rpx 12rpx rgba(255, 193, 7, 0.3)"]])], [".disabled", _uM([["backgroundImage", "none"], ["backgroundColor", "#dddddd"], ["color", "#999999"], ["boxShadow", "none"]])]])], ["agree-row", _pS(_uM([["alignItems", "flex-start"]]))], ["agree-content", _pS(_uM([["flexGrow", 1], ["flexShrink", 1], ["flexBasis", "0%"], ["marginLeft", "10rpx"]]))], ["agree-text", _pS(_uM([["fontSize", "24rpx"], ["color", "#999999"], ["lineHeight", 1.6]]))], ["link-text", _pS(_uM([["color", "#00b894"], ["borderBottomWidth", "1rpx"], ["borderBottomStyle", "solid"], ["borderBottomColor", "#00b894"]]))], ["footer-section", _pS(_uM([["marginTop", "auto"]]))], ["divider-row", _pS(_uM([["marginBottom", "40rpx"], ["alignItems", "center"]]))], ["line", _pS(_uM([["flexGrow", 1], ["flexShrink", 1], ["flexBasis", "0%"], ["height", "1rpx"], ["backgroundColor", "#dddddd"]]))], ["divider-text", _pS(_uM([["fontSize", "26rpx"], ["color", "#999999"], ["marginTop", 0], ["marginRight", "20rpx"], ["marginBottom", 0], ["marginLeft", "20rpx"]]))], ["methods-row", _pS(_uM([["justifyContent", "center"], ["marginBottom", "40rpx"]]))], ["method-item", _pS(_uM([["marginRight", "60rpx"], ["alignItems", "center"], ["marginRight:last-child", 0]]))], ["icon-box", _pS(_uM([["width", "80rpx"], ["height", "80rpx"], ["borderTopLeftRadius", "40rpx"], ["borderTopRightRadius", "40rpx"], ["borderBottomRightRadius", "40rpx"], ["borderBottomLeftRadius", "40rpx"], ["justifyContent", "center"], ["alignItems", "center"], ["marginBottom", "15rpx"]]))], ["blue-bg", _pS(_uM([["backgroundImage", "linear-gradient(135deg, #4a90e2, #67b26f)"], ["backgroundColor", "rgba(0,0,0,0)"]]))], ["green-bg", _pS(_uM([["backgroundImage", "linear-gradient(135deg, #00b894, #00cec9)"], ["backgroundColor", "rgba(0,0,0,0)"]]))], ["method-name", _pS(_uM([["fontSize", "26rpx"], ["color", "#666666"]]))], ["modal-mask", _pS(_uM([["position", "fixed"], ["top", 0], ["left", 0], ["right", 0], ["bottom", 0], ["backgroundColor", "rgba(0,0,0,0.5)"], ["justifyContent", "center"], ["alignItems", "center"], ["zIndex", 100]]))], ["modal-box", _pS(_uM([["backgroundColor", "#ffffff"], ["borderTopLeftRadius", "20rpx"], ["borderTopRightRadius", "20rpx"], ["borderBottomRightRadius", "20rpx"], ["borderBottomLeftRadius", "20rpx"], ["paddingTop", "40rpx"], ["paddingRight", "30rpx"], ["paddingBottom", "40rpx"], ["paddingLeft", "30rpx"], ["width", "600rpx"], ["maxHeight", "800rpx"], ["flexDirection", "column"]]))], ["modal-title", _pS(_uM([["fontSize", "36rpx"], ["fontWeight", "bold"], ["color", "#333333"], ["textAlign", "center"], ["marginBottom", "20rpx"]]))], ["modal-scroll", _pS(_uM([["flexGrow", 1], ["flexShrink", 1], ["flexBasis", "0%"], ["marginBottom", "20rpx"]]))], ["modal-welcome", _pS(_uM([["fontSize", "28rpx"], ["color", "#333333"], ["marginBottom", "15rpx"]]))], ["modal-desc", _pS(_uM([["fontSize", "26rpx"], ["color", "#666666"], ["lineHeight", 1.6], ["marginBottom", "15rpx"]]))], ["modal-link", _pS(_uM([["color", "#00b894"], ["borderBottomWidth", "1rpx"], ["borderBottomStyle", "solid"], ["borderBottomColor", "#00b894"]]))], ["modal-list", _pS(_uM([["fontSize", "26rpx"], ["color", "#666666"], ["lineHeight", 1.6], ["marginBottom", "10rpx"]]))], ["modal-footer", _pS(_uM([["fontSize", "26rpx"], ["color", "#666666"], ["lineHeight", 1.6], ["marginBottom", "10rpx"]]))], ["modal-btns", _pS(_uM([["borderTopWidth", "1rpx"], ["borderTopStyle", "solid"], ["borderTopColor", "#eeeeee"], ["paddingTop", "20rpx"]]))], ["modal-btn", _uM([["", _uM([["flexGrow", 1], ["flexShrink", 1], ["flexBasis", "0%"], ["textAlign", "center"], ["fontSize", "28rpx"], ["fontWeight", "bold"], ["paddingTop", "15rpx"], ["paddingRight", 0], ["paddingBottom", "15rpx"], ["paddingLeft", 0]])], [".reject", _uM([["color", "#999999"], ["marginRight", "20rpx"]])], [".agree", _uM([["color", "#00b894"]])]])], ["row-between", _pS(_uM([["flexDirection", "row"], ["justifyContent", "space-between"], ["alignItems", "center"]]))], ["row-start", _pS(_uM([["flexDirection", "row"], ["alignItems", "flex-start"]]))], ["row-center", _pS(_uM([["flexDirection", "row"], ["justifyContent", "center"], ["alignItems", "center"]]))], ["column-center", _pS(_uM([["flexDirection", "column"], ["justifyContent", "center"], ["alignItems", "center"]]))]])]