You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

forget-password.vue 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view>
  3. <u-form :model="form" ref="form1" label-width=180>
  4. <u-form-item label="用户名">
  5. <u-input placeholder='请输入用户名' type="text" v-model="state.form.accountId" />
  6. <text @click="search" class="search">查询</text>
  7. </u-form-item>
  8. <u-form-item label="手机号" v-if="state.isShow">
  9. <u-input placeholder='手机号' type="number" v-model="state.form.agentTel" disabled />
  10. </u-form-item>
  11. <u-form-item label="验证码" v-if="state.isShow">
  12. <u-input v-model="state.form.code" placeholder='请输入短信验证码' />
  13. <text @click="getCode" v-if="waitTime==0" class="search">获取验证码</text>
  14. <text class="search" v-else>{{waitTime}}后重试</text>
  15. </u-form-item>
  16. <u-form-item label="新密码" v-if="state.isShow">
  17. <u-input placeholder='请输入' v-model="state.form.password" type='password' />
  18. </u-form-item>
  19. <u-form-item label="确认密码" v-if="state.isShow">
  20. <u-input placeholder='请输入' v-model="state.form.confirmPassword" type='password' />
  21. </u-form-item>
  22. </u-form>
  23. <button @click='goLogin()' v-if="state.isShow">确定</button>
  24. </view>
  25. </template>
  26. <script setup lang="ts">
  27. import { reactive, ref } from "vue";
  28. import { navTo } from "@/utils/utils";
  29. import {
  30. request, requestNew
  31. } from "@/utils/network/request.js";
  32. import {
  33. sendMessage,
  34. checkCode,
  35. queryPhoneApi,
  36. forgetPassApi
  37. } from "@/utils/network/api.js";
  38. import { stringToJson } from "@/utils/network/encryption";
  39. import {
  40. msg
  41. } from "@/utils/utils";
  42. let waitTime = ref(0);
  43. const state = reactive({
  44. form: {
  45. accountId: '',
  46. agentTel: '',
  47. code: '',
  48. password: '',
  49. confirmPassword: '',
  50. },
  51. isShow: false,
  52. });
  53. const search = () => {
  54. if (!state.form.accountId) {
  55. msg('请输入用户名')
  56. return;
  57. }
  58. let options = {
  59. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  60. data: {
  61. accountId: state.form.accountId
  62. }, //请求参数
  63. method: "POST", //提交方式(默认POST)
  64. showLoading: true, //是否显示加载中(默认显示)
  65. };
  66. //调用方式
  67. request(queryPhoneApi, options)
  68. .then((res) => {
  69. let data = stringToJson(res.bizContent)
  70. state.form.agentTel = data.message
  71. state.isShow = true;
  72. })
  73. .catch((err) => {
  74. console.log(err);
  75. });
  76. console.log("查询")
  77. }
  78. const getCode = () => {
  79. console.log(123);
  80. if (state.form.agentTel) {
  81. sendCodeApi()
  82. codeInterval()
  83. } else {
  84. uni.showToast({
  85. title: '请输入手机号',
  86. icon: 'none'
  87. });
  88. }
  89. }
  90. // 发送验证码
  91. const sendCodeApi = (type) => {
  92. //参数说明
  93. let options = {
  94. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  95. data: {
  96. mobile: state.form.agentTel
  97. }, //请求参数
  98. method: "POST", //提交方式(默认POST)
  99. showLoading: true, //是否显示加载中(默认显示)
  100. };
  101. //调用方式
  102. requestNew(sendMessage, options)
  103. .then((res) => {
  104. let data = res
  105. console.log(data, "#################");
  106. if (data.info == "成功.") {
  107. console.log('######################CCCCCCCCCCCCCCCCC');
  108. }
  109. })
  110. .catch((err) => {
  111. console.log(err);
  112. });
  113. }
  114. //倒计时函数
  115. const codeInterval = () => {
  116. waitTime.value = 60
  117. let timer = setInterval(() => {
  118. if (waitTime.value == 1) {
  119. clearInterval(timer)
  120. }
  121. waitTime.value -= 1
  122. }, 1000)
  123. }
  124. // 校验验证码
  125. const checkCodeRequest = () => {
  126. const options = {
  127. type: 2,
  128. data: {
  129. mobile: state.form.agentTel,
  130. code: state.form.code
  131. },
  132. method: "POST",
  133. showLoading: true,
  134. };
  135. return new Promise(async (resolve, reject) => {
  136. const res = await request(checkCode, options);
  137. const data = stringToJson(res.bizContent);
  138. resolve(data);
  139. }).catch((error) => {
  140. reject(error);
  141. });
  142. }
  143. const goLogin = () => {
  144. submit()
  145. }
  146. const submit = () => {
  147. if (!state.form.accountId) {
  148. msg("请输入用户名!");
  149. return;
  150. }
  151. if (!state.form.code) {
  152. msg('请输入验证码')
  153. return;
  154. }
  155. if (!state.form.password) {
  156. msg("请输入密码!");
  157. return;
  158. }
  159. if (!state.form.confirmPassword) {
  160. msg("请确认密码");
  161. return;
  162. }
  163. if (state.form.password != state.form.confirmPassword) {
  164. msg("请确认密码输入是否一致");
  165. return;
  166. }
  167. checkCodeRequest().then((val : any) => {
  168. let options = {
  169. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  170. data: {
  171. accountId: state.form.accountId,
  172. agentTel: state.form.agentTel,
  173. passWord: state.form.password,
  174. confirmPassword: state.form.confirmPassword
  175. }, //请求参数
  176. method: "POST", //提交方式(默认POST)
  177. showLoading: true, //是否显示加载中(默认显示)
  178. };
  179. //调用方式
  180. request(forgetPassApi, options).then((res) => {
  181. msg("密码修改成功");
  182. setTimeout(() => {
  183. uni.navigateBack({
  184. delta: 1
  185. })
  186. }, 1500)
  187. })
  188. .catch((err) => {
  189. console.log(err);
  190. });
  191. })
  192. }
  193. </script>
  194. <style scoped>
  195. ::v-deep .u-form-item--right__content__slot {
  196. display: flex !important;
  197. }
  198. ::v-deep .u-form-item__body {
  199. padding: 0 40rpx;
  200. font-size: 32rpx;
  201. }
  202. ::v-deep .u-input__input {
  203. font-size: 32rpx !important;
  204. }
  205. ::v-deep .u-size-mini {
  206. font-size: 28rpx !important;
  207. padding: 12px 32rpx !important;
  208. white-space: nowrap;
  209. }
  210. button {
  211. width: 75%;
  212. height: 80rpx;
  213. margin-top: 60rpx;
  214. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  215. border-radius: 40rpx;
  216. font-size: 32rpx;
  217. font-weight: 400;
  218. color: #ffffff;
  219. line-height: 80rpx;
  220. }
  221. ::v-deep .u-form-item--right__content__slot {
  222. display: flex !important;
  223. align-items: center;
  224. }
  225. .search{
  226. color: #ffffff;
  227. border-color: #19be6b;
  228. background-color: #19be6b;
  229. font-size: 28rpx !important;
  230. padding: 8px 30rpx !important;
  231. white-space: nowrap;
  232. height: 30rpx;
  233. line-height: 30rpx;
  234. border-radius: 16rpx;
  235. }
  236. </style>