phone.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <script>
  2. import { clientLogin, sendMsg } from '@/api/newLogin.js'
  3. export default {
  4. data() {
  5. return {
  6. phone: '',
  7. password: '',
  8. countdown: 60,
  9. timer: null,
  10. isSendingCode: false,
  11. isBinding: false,
  12. isPwdHide: true,
  13. isPasswordLogin: true,
  14. useCodeLogin: false,
  15. showCaptcha: false, // 弹窗显隐
  16. imgCode: '', // 用户填写的图形验证码
  17. captchaImg: '', // 图形验证码图片地址
  18. captchaKey: '' // 后端返回验证码标识
  19. }
  20. },
  21. computed: {
  22. canGetCode() {
  23. return this.phone && this.validatePhone(this.phone) && !this.isSendingCode && this.countdown === 60
  24. },
  25. // canBind() {
  26. // return this.phone && this.validatePhone(this.phone) && this.code && this.code.length === 6 && !this.isBinding
  27. // }
  28. },
  29. onShow() {
  30. this.password = ''
  31. },
  32. methods: {
  33. validatePhone(phone) {
  34. const reg = /^1[3-9]\d{9}$/
  35. return reg.test(phone)
  36. },
  37. nextStep() {
  38. if (!this.phone) {
  39. uni.showToast({
  40. title: '请输入手机号',
  41. icon: 'none'
  42. })
  43. return
  44. }
  45. if (!this.validatePhone(this.phone)) {
  46. uni.showToast({
  47. title: '请输入正确的手机号',
  48. icon: 'none'
  49. })
  50. return
  51. }
  52. if (!this.isPasswordLogin) {
  53. this.showCaptcha = true
  54. }
  55. },
  56. //登录
  57. loginPhoneFun() {
  58. var _this = this;
  59. if (this.isBinding) return
  60. if (!this.phone) {
  61. uni.showToast({
  62. title: '请输入手机号',
  63. icon: 'none'
  64. })
  65. return
  66. }
  67. if (!this.validatePhone(this.phone)) {
  68. uni.showToast({
  69. title: '请输入正确的手机号',
  70. icon: 'none'
  71. })
  72. return
  73. }
  74. if (!this.password && this.isPasswordLogin) {
  75. uni.showToast({
  76. title: '请输入密码',
  77. icon: 'none'
  78. })
  79. return
  80. }
  81. this.isBinding = true
  82. clientLogin({
  83. //openId: uni.getStorageSync('wx_copenid'),
  84. userType: '2',
  85. phone: _this.phone,
  86. codeSwitch: 'false',//是否开启验证码登录 true-是 false-否
  87. passWord: this.passWord
  88. }).then(res => {
  89. if (res.data.code == 200) {
  90. uni.showToast({
  91. title: '登录成功',
  92. icon: 'success'
  93. })
  94. uni.setStorageSync('wx_phone', _this.phone)
  95. _this.isBinding = false;
  96. _this.back();
  97. }
  98. })
  99. },
  100. back() {
  101. let pages = getCurrentPages();
  102. if (pages.length >= 2) {
  103. let prevPage = pages[pages.length - 2];
  104. let prevRoute = prevPage.route;
  105. if (prevRoute && prevRoute !== 'pages/index/index') {
  106. if (prevRoute.startsWith('pages/')) {
  107. uni.switchTab({
  108. url: '/' + prevRoute
  109. })
  110. } else {
  111. uni.navigateBack({
  112. delta: 1,
  113. fail: () => {
  114. uni.switchTab({
  115. url: '/pages/index/index'
  116. })
  117. }
  118. })
  119. }
  120. } else {
  121. uni.switchTab({
  122. url: '/pages/index/index'
  123. })
  124. }
  125. } else {
  126. uni.switchTab({
  127. url: '/pages/index/index'
  128. })
  129. }
  130. },
  131. //图形验证码提交
  132. submitImgCode() {
  133. if (!this.imgCode) {
  134. uni.showToast({
  135. title: '请输入验证码',
  136. icon: 'none'
  137. })
  138. return
  139. }
  140. sendMsg33333({ uuid:this.uuid,imgCode:this.imgCode}).then(res => {
  141. console.log(res)
  142. if (res.data.code == 200) {
  143. uni.navigateTo({
  144. url: `/setting/myNew/useCodeLogin?phone=` + this.phone
  145. })
  146. }
  147. })
  148. },
  149. //忘记密码
  150. forgetPassword() {
  151. uni.navigateTo({
  152. url: `/setting/myNew/forgetPassword?phone=` + this.phone
  153. })
  154. }
  155. },
  156. beforeDestroy() {
  157. if (this.timer) {
  158. clearInterval(this.timer)
  159. this.timer = null
  160. }
  161. }
  162. }
  163. </script>
  164. <template>
  165. <view class="sett-box">
  166. <!-- 放在页面最顶部,拦截自动填充核心代码 -->
  167. <input type="text" name="username" style="position:absolute;opacity:0;width:0;height:0;z-index:-99;" />
  168. <input type="password" name="password" style="position:absolute;opacity:0;width:0;height:0;z-index:-99;" />
  169. <view class="greeting-area">
  170. <view class="bubble-text">您好,欢迎使用广誉源!</view>
  171. </view>
  172. <view class="greeting-area1"></view>
  173. <view class="content">
  174. <view class="input-box">
  175. <u-input v-model="phone" type="number" border="none" maxlength="11" placeholder="请输入手机号"
  176. placeholder-style="font-weight: 400;font-size: 30rpx;color: #C9CDD4;" class="input-item">
  177. <!-- <template slot="prefix">
  178. <view class="label">
  179. <text>+86</text>
  180. <u-line length="38rpx" color="#ccc" margin="0 12rpx 0 20rpx" direction="col"></u-line>
  181. </view>
  182. </template> -->
  183. </u-input>
  184. </view>
  185. <view class="input-box" v-if="isPasswordLogin">
  186. <u-input v-model="password" customStyle="font-family: monospace" autocomplete="off" border="none"
  187. :password="isPwdHide" maxlength="20" customClass="pwd-star" placeholder="请输入密码"
  188. placeholder-style="font-weight: 400;font-size: 30rpx;color: #C9CDD4;" class="input-item">
  189. <!-- <template #suffix>
  190. <image v-if="isPwdHide" src="/static/login/closeEye.png" @click="isPwdHide = !isPwdHide" class="captcha-img"></image>
  191. <image v-if="!isPwdHide" src="/static/login/openEye.png" @click="isPwdHide = !isPwdHide" class="captcha-img"></image>
  192. </template> -->
  193. </u-input>
  194. </view>
  195. <view class="bind-btn">
  196. <u-button v-if="isPasswordLogin || useCodeLogin" :loading="isBinding" type="primary"
  197. @click="loginPhoneFun">登录</u-button>
  198. <u-button v-if="!isPasswordLogin" :loading="isBinding" type="primary" @click="nextStep">下一步</u-button>
  199. </view>
  200. <view class="textBox">
  201. <view class="text1" v-if="isPasswordLogin" @click="isPasswordLogin = false">验证码登录</view>
  202. <view class="text1" v-if="!isPasswordLogin" @click="isPasswordLogin = true">密码登录</view>
  203. <view class="text2" v-if="isPasswordLogin" @click="forgetPassword">忘记密码</view>
  204. </view>
  205. </view>
  206. <!-- //myNew/forgetPassword -->
  207. <!-- 图形验证码弹窗 -->
  208. <u-popup :show="showCaptcha" mode="center" border-radius="12">
  209. <view class="captcha-box">
  210. <view class="captcha-title">
  211. <view>请输入下方图形验证码</view>
  212. <u-icon custom-style="position: relative;left:90rpx ;" name="close" color="#C9CDD4" size="20"
  213. @click="showCaptcha = false"></u-icon>
  214. </view>
  215. <view style="padding: 0 48rpx;margin-top: 48rpx;">
  216. <view style="display: flex;justify-content: space-between;height: 106rpx;border-bottom: 1rpx solid #E7E7E7;">
  217. <!-- 验证码输入框,唤起全字符键盘 -->
  218. <u-input v-model="imgCode" placeholder="请输入图形验证码" :focus="showCaptcha" type="text" maxlength="4"
  219. border="none" placeholder-style="font-weight: 400;font-size: 30rpx;color: #C9CDD4;"></u-input>
  220. <!-- 图形验证码图片,点击刷新 -->
  221. <image :src="captchaImg" @click="refreshCaptcha" class="captcha-img"></image>
  222. </view>
  223. <view class="text" @click="submitImgCode">看不清? 换一张</view>
  224. <u-button class="submitImgCode" @click="submitImgCode" block>确定</u-button>
  225. </view>
  226. </view>
  227. </u-popup>
  228. </view>
  229. </template>
  230. <style scoped lang="scss">
  231. ::v-deep .u-popup__content {
  232. background-color: #00000000;
  233. }
  234. .captcha-box {
  235. width: 622rpx;
  236. background: #FFFFFF;
  237. border-radius: 32rpx 32rpx 32rpx 32rpx;
  238. .captcha-title {
  239. display: flex;
  240. justify-content: center;
  241. align-items: center;
  242. font-weight: 500;
  243. font-size: 32rpx;
  244. color: #333333;
  245. text-align: center;
  246. padding: 32rpx 0;
  247. border-bottom: 1rpx solid #E7E7E7;
  248. }
  249. .captcha-img {
  250. //width: 100%;
  251. width: 200rpx;
  252. height: 106rpx;
  253. }
  254. .submitImgCode {
  255. width: 526rpx;
  256. height: 80rpx;
  257. background: linear-gradient(263deg, #45FFD7 0%, #7FFFBD 100%);
  258. border-radius: 60rpx 60rpx 60rpx 60rpx;
  259. margin-top: 48rpx;
  260. font-weight: 500;
  261. font-size: 32rpx;
  262. color: #1D2129;
  263. text-align: center;
  264. margin-bottom: 48rpx;
  265. }
  266. .text {
  267. margin-top: 12rpx;
  268. font-weight: 400;
  269. font-size: 28rpx;
  270. color: #86909C;
  271. text-align: right;
  272. }
  273. .u-input {}
  274. }
  275. .sett-box {
  276. background: #ffffff;
  277. width: 100%;
  278. min-height: 100vh;
  279. line-height: 1;
  280. position: relative;
  281. //padding: 36rpx 40rpx;
  282. .greeting-area1 {
  283. height: 438rpx;
  284. }
  285. .greeting-area {
  286. background-image: url('/static/login/loginBg.png');
  287. background-size: 100%;
  288. background-repeat: no-repeat;
  289. padding-left: 64rpx;
  290. padding-top: 256rpx;
  291. top: 0;
  292. z-index: 4;
  293. height: 438rpx;
  294. position: absolute;
  295. overflow: hidden;
  296. width: 100%;
  297. .bubble-text {
  298. font-weight: 500;
  299. font-size: 52rpx;
  300. color: #1D2129
  301. }
  302. }
  303. .content {
  304. padding: 0 64rpx;
  305. .textBox {
  306. display: flex;
  307. justify-content: space-between;
  308. font-size: 28rpx;
  309. padding: 16rpx 42rpx 0 42rpx;
  310. }
  311. .text1 {
  312. font-weight: 400;
  313. font-size: 28rpx;
  314. color: #19D29B;
  315. }
  316. .text2 {
  317. font-weight: 400;
  318. font-size: 28rpx;
  319. color: #86909C;
  320. text-align: center;
  321. }
  322. }
  323. }
  324. .input-box {
  325. width: 622rpx;
  326. height: 110rpx;
  327. background: #FFFFFF;
  328. display: flex;
  329. align-items: center;
  330. border-bottom: 1rpx solid #E7E7E7;
  331. .label {
  332. display: flex;
  333. }
  334. .input-item {
  335. flex: 1;
  336. }
  337. ::v-deep .uni-input-input {
  338. font-weight: 500;
  339. font-size: 30rpx;
  340. color: #1D2129;
  341. }
  342. .captcha-img{
  343. width: 30rpx;
  344. height: 30rpx;
  345. }
  346. }
  347. .code-box {
  348. .code-input {
  349. flex: 1;
  350. }
  351. .code-btn {
  352. width: 200rpx;
  353. text-align: right;
  354. font-size: 28rpx;
  355. color: #2DB1A8;
  356. line-height: 88rpx;
  357. &.disabled {
  358. color: #2DB1A8;
  359. }
  360. }
  361. }
  362. .bind-btn {
  363. margin-top: 120rpx;
  364. ::v-deep .u-button {
  365. width: 622rpx;
  366. height: 88rpx;
  367. background: #333335;
  368. border-radius: 60rpx 60rpx 60rpx 60rpx;
  369. border: none;
  370. font-weight: 500;
  371. font-size: 32rpx;
  372. color: #fff;
  373. text-align: center;
  374. }
  375. ::v-deep .u-button--disabled {
  376. background: #E0E0E0 !important;
  377. color: #999 !important;
  378. }
  379. }
  380. </style>