index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view class="login">
  3. <view class="login-form">
  4. <uv-form
  5. labelPosition="top"
  6. labelWidth="80"
  7. :labelStyle="labelStyle"
  8. :model="formData"
  9. ref="formRef"
  10. :rules="rules"
  11. >
  12. <uv-form-item label="手机号" prop="userName" borderBottom>
  13. <view class="pbone-input">
  14. <input
  15. class="login-input"
  16. clearable
  17. maxlength="11"
  18. v-model="formData.userName"
  19. border="none"
  20. type="number"
  21. placeholder="请输入手机号"
  22. />
  23. </view>
  24. </uv-form-item>
  25. <uv-form-item label="验证码" prop="code" borderBottom>
  26. <view class="pbone-input">
  27. <input
  28. class="login-input"
  29. clearable
  30. v-model="formData.code"
  31. border="none"
  32. type="number"
  33. placeholder="请输入验证码"
  34. />
  35. <view class="code">
  36. <uv-code
  37. ref="codeRef"
  38. @change="codeChange"
  39. @start="codeDisabledChange(true)"
  40. @end="codeDisabledChange(false)"
  41. changeText="Xs"
  42. ></uv-code>
  43. <uv-button
  44. @click="getCode"
  45. :disabled="codeDisabled || !codeDisabledType"
  46. :text="code"
  47. :custom-style="customStyle"
  48. />
  49. </view>
  50. </view>
  51. </uv-form-item>
  52. <uv-form-item label="密码" prop="p1" borderBottom>
  53. <view class="pbone-input">
  54. <input
  55. class="login-input"
  56. clearable
  57. v-model="formData.p1"
  58. border="none"
  59. type="password"
  60. placeholder="请输入密码"
  61. />
  62. </view>
  63. </uv-form-item>
  64. <uv-form-item label="确认密码" prop="p2" borderBottom>
  65. <view class="pbone-input">
  66. <input
  67. class="login-input"
  68. clearable
  69. v-model="formData.p2"
  70. border="none"
  71. type="password"
  72. placeholder="请输入密码"
  73. />
  74. </view>
  75. </uv-form-item>
  76. </uv-form>
  77. <view class="tips">
  78. <text
  79. >密码由8~16位含有大小写字母、数字、!#$%^&*@符号且不能有三位连续的数字组成(如123)</text
  80. >
  81. </view>
  82. <view class="login-btn">
  83. <button class="btn" @click="submit">提交</button>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script setup lang="ts">
  89. import { reactive, ref, computed } from 'vue'
  90. import { getMobileUpdApi, postUserUpdApi } from '@/service/modules/login'
  91. import { isValidPhoneNumber } from '@/utils'
  92. const labelStyle = {
  93. fontSize: '32rpx',
  94. fontWeight: 600,
  95. color: '#333'
  96. }
  97. let validatePassword = (rule: any, value: any, callback: any) => {
  98. var regA = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!#$%^&*@])[\da-zA-Z!#$%^&*@]{8,16}$/ //密码必须是8位以上、必须含有字母、数字、特殊符号
  99. var regB = /(123|234|345|456|567|678|789|012)/ //不能有3个连续数字
  100. if (!value) {
  101. callback(new Error('密码不能为空'))
  102. }
  103. if (!regA.test(value)) {
  104. callback(new Error('密码必须是8~16位、必须含有大小写字母、数字、特殊符号'))
  105. } else if (regB.test(value)) {
  106. callback(new Error('不能有3个连续数字'))
  107. } else {
  108. callback()
  109. }
  110. }
  111. var validateCheckPass = (rule: any, value: any, callback: any) => {
  112. if (value !== formData.p1) {
  113. callback(new Error('两次输入密码不一致'))
  114. } else {
  115. callback()
  116. }
  117. }
  118. const rules = reactive({
  119. userName: {
  120. type: 'string',
  121. required: true,
  122. trigger: ['blur']
  123. },
  124. code: {
  125. type: 'string',
  126. required: true,
  127. trigger: ['blur']
  128. },
  129. p1: {
  130. type: 'string',
  131. required: true,
  132. trigger: ['blur'],
  133. validator: validatePassword
  134. },
  135. p2: {
  136. type: 'string',
  137. required: true,
  138. validator: validateCheckPass,
  139. trigger: ['blur']
  140. }
  141. })
  142. const formRef = ref()
  143. const formData = reactive({
  144. userName: '',
  145. p1: '',
  146. p2: '',
  147. code: ''
  148. })
  149. // 验证码
  150. const code = ref('获取验证码')
  151. const codeRef = ref()
  152. const codeDisabled = ref(false)
  153. function codeChange(text: string) {
  154. code.value = text
  155. }
  156. const codeDisabledChange = (flag: boolean) => {
  157. codeDisabled.value = flag
  158. }
  159. let codeDisabledType = computed(() => {
  160. return formData.userName && !codeDisabled.value
  161. })
  162. // 获取验证码按钮样式
  163. const customStyle = {
  164. height: '64rpx',
  165. width: '200rpx',
  166. background: 'rgba(110,182,87, .1)',
  167. borderRadius: '16rpx',
  168. color: '#6eb657',
  169. fontWeight: 500,
  170. lineHeight: '64rpx',
  171. fontSize: '28rpx'
  172. }
  173. async function getCode() {
  174. if (!isValidPhoneNumber(formData.userName)) {
  175. return uni.showToast({
  176. title: '请检查手机号码格式',
  177. icon: 'none'
  178. })
  179. }
  180. // 获取验证码
  181. uni.showLoading({
  182. title: '正在获取验证码'
  183. })
  184. const res = await getMobileUpdApi(formData.userName)
  185. uni.hideLoading()
  186. if (!res.data) {
  187. uni.showToast({
  188. title: res.msg,
  189. icon: 'none'
  190. })
  191. } else {
  192. uni.showToast({
  193. title: res.msg,
  194. icon: 'none'
  195. })
  196. }
  197. codeRef.value.start()
  198. }
  199. const submit = () => {
  200. if (!isValidPhoneNumber(formData.userName)) {
  201. return uni.showToast({
  202. title: '请检查手机号码格式',
  203. icon: 'none'
  204. })
  205. }
  206. formRef.value.validate().then(async () => {
  207. const res = await postUserUpdApi(formData)
  208. if (res.code === 0) {
  209. uni.showToast({
  210. icon: 'none',
  211. title: '修改成功'
  212. })
  213. setTimeout(() => {
  214. uni.reLaunch({
  215. url: '/pages/login/index'
  216. })
  217. }, 1000)
  218. }
  219. })
  220. }
  221. </script>
  222. <style lang="scss" scoped>
  223. .login {
  224. padding: 0 50rpx;
  225. }
  226. .login-bg {
  227. position: absolute;
  228. z-index: -333;
  229. top: 0;
  230. left: 0;
  231. right: 0;
  232. height: 800rpx;
  233. background: linear-gradient(#f8f8f0 0%, rgba(255, 255, 255, 0) 100%);
  234. }
  235. .login-title {
  236. margin-top: 300rpx;
  237. color: #333;
  238. font-size: 56rpx;
  239. font-weight: 500;
  240. }
  241. .login-form {
  242. margin-top: 80rpx;
  243. .pbone-input {
  244. display: flex;
  245. justify-content: space-between;
  246. align-items: center;
  247. }
  248. .forgot-password {
  249. color: #999;
  250. }
  251. .login-input {
  252. margin: 20rpx 0 0 10rpx;
  253. }
  254. :deep(.uv-form-item) {
  255. margin-bottom: 40rpx;
  256. }
  257. .agreement {
  258. display: flex;
  259. font-size: 26rpx;
  260. font-weight: 400;
  261. line-height: 40rpx;
  262. .read-content {
  263. .primarily-text {
  264. color: #6eb657;
  265. }
  266. }
  267. }
  268. .login-btn {
  269. margin-top: 70rpx;
  270. .btn {
  271. width: 640rpx;
  272. height: 96rpx;
  273. border-radius: 200rpx;
  274. background-color: #6eb657;
  275. text-align: center;
  276. color: #fff;
  277. font-size: 40rpx;
  278. font-weight: 600;
  279. }
  280. }
  281. .login-password {
  282. margin-top: 50rpx;
  283. color: #999;
  284. font-size: 32rpx;
  285. text-align: center;
  286. font-weight: 400;
  287. line-height: 60rpx;
  288. }
  289. }
  290. .tips {
  291. color: #666;
  292. }
  293. </style>