mobile.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <view>
  3. <view class="userinfo">
  4. <image class="userinfo-avatar" :src="userInfo.avatarUrl" background-size="cover"></image>
  5. <text class="userinfo-nickname">{{userInfo.nickName}}</text>
  6. </view>
  7. <view class="separate"></view>
  8. <view>
  9. <view>
  10. <view class="login-title">关联手机号</view>
  11. <form @submit="bindLoginMobilecode">
  12. <form @submit="bindGetPassCode">
  13. <view class="login">
  14. <view class="first-line"><input type="digit" name="mobile" @input="bindInputMobile" placeholder="输入手机号" v-model="mobile"
  15. auto-focus /></view>
  16. <view class="second-line">
  17. <input type="digit" name="code" placeholder="四位验证码" />
  18. <button @tap="countDownPassCode" :disabled="disableGetMobileCode">{{getCodeButtonText}}</button>
  19. </view>
  20. </view>
  21. </form>
  22. <view class="third-line"><button formType="submit" :disabled="disableSubmitMobileCode">提交</button></view>
  23. </form>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. const util = require("@/utils/util.js");
  30. const api = require('@/utils/api.js');
  31. const app = getApp();
  32. export default {
  33. data() {
  34. return {
  35. mobile: '',
  36. userInfo: app.globalData.userInfo,
  37. disableGetMobileCode: false,
  38. disableSubmitMobileCode: true,
  39. getCodeButtonText: '获取验证码'
  40. }
  41. },
  42. methods: {
  43. bindCheckMobile: function(mobile) {
  44. if (!mobile) {
  45. util.toast('请输入手机号码')
  46. return false
  47. }
  48. if (!mobile.match(/^1[3-9][0-9]\d{8}$/)) {
  49. util.toast('手机号格式不正确,仅支持国内手机号码')
  50. return false
  51. }
  52. return true
  53. },
  54. bindGetPassCode: function(e) {
  55. this.disableGetMobileCode = true
  56. },
  57. bindInputMobile: function(e) {
  58. this.mobile = e.detail.value
  59. },
  60. countDownPassCode: function() {
  61. var that = this
  62. if (!that.bindCheckMobile(that.mobile)) {
  63. return
  64. }
  65. util.request(api.SmsCode, {
  66. phone: that.mobile
  67. }, 'POST', 'application/json').then(function(res) {
  68. if (res.errno == 0) {
  69. util.toast('发送成功')
  70. var pages = getCurrentPages()
  71. var i = 60;
  72. var intervalId = setInterval(function() {
  73. i--
  74. if (i <= 0) {
  75. pages[pages.length - 1].disableGetMobileCode = false
  76. pages[pages.length - 1].disableSubmitMobileCode = false
  77. pages[pages.length - 1].getCodeButtonText = '获取验证码'
  78. clearInterval(intervalId)
  79. } else {
  80. pages[pages.length - 1].getCodeButtonText = i
  81. pages[pages.length - 1].disableGetMobileCode = true
  82. pages[pages.length - 1].disableSubmitMobileCode = false
  83. }
  84. }, 1000);
  85. } else {
  86. util.toast('发送失败')
  87. }
  88. });
  89. },
  90. bindLoginMobilecode: function(e) {
  91. var mobile = this.mobile;
  92. if (!this.bindCheckMobile(mobile)) {
  93. return
  94. }
  95. if (!(e.detail.value.code && e.detail.value.code.length === 4)) {
  96. return
  97. }
  98. util.request(api.BindMobile, {
  99. mobile_code: e.detail.value.code,
  100. mobile: mobile
  101. }, "POST", "application/json").then(function(res) {
  102. if (res.errno === 0) {
  103. util.toast('操作成功')
  104. uni.switchTab({
  105. url: '/pages/ucenter/index/index'
  106. });
  107. } else {
  108. util.toast('验证码错误')
  109. }
  110. })
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss">
  116. .userinfo {
  117. display: flex;
  118. flex-direction: column;
  119. align-items: center;
  120. padding-bottom: 25rpx;
  121. background: linear-gradient(to bottom, #FCD33D 0%, #FFF6D7 100%);
  122. }
  123. .userinfo-avatar {
  124. width: 100rpx;
  125. height: 100rpx;
  126. border-radius: 50%;
  127. margin-top: 20rpx;
  128. margin-bottom: 25rpx;
  129. }
  130. .userinfo-nickname {
  131. color: #272727;
  132. font-size: 28rpx;
  133. line-height: 40rpx;
  134. }
  135. .separate {
  136. height: 18rpx;
  137. background-color: #f2f2f2;
  138. }
  139. .zichan {
  140. display: flex;
  141. flex-direction: column;
  142. }
  143. .zichan .first-line {
  144. display: flex;
  145. flex-direction: row;
  146. justify-content: space-between;
  147. font-size: 27rpx;
  148. margin-left: 20rpx;
  149. margin-top: 20rpx;
  150. margin-bottom: 20rpx;
  151. }
  152. .zichan .second-line {
  153. padding-top: 15rpx;
  154. padding-bottom: 15rpx;
  155. border-top: 1rpx solid #F6F6F6;
  156. border-bottom: 1rpx solid #F6F6F6;
  157. height: max-content;
  158. }
  159. .long-view {
  160. display: flex;
  161. flex-direction: row;
  162. width: 1850rpx;
  163. }
  164. .zichan .second-line .item {
  165. width: 560rpx;
  166. height: 264rpx;
  167. margin-left: 20rpx;
  168. }
  169. .zichan .second-line .item .image {
  170. height: 264rpx;
  171. }
  172. .zichan .second-line .desc {
  173. position: relative;
  174. top: -262rpx;
  175. left: 0;
  176. width: 560rpx;
  177. height: 264rpx;
  178. background-color: rgba(0, 0, 0, 0.3);
  179. border-radius: 5px;
  180. text-align: center;
  181. color: #fff;
  182. display: flex;
  183. flex-direction: column;
  184. justify-content: center;
  185. font-size: 25rpx;
  186. }
  187. .desc-line {
  188. margin-top: 5rpx;
  189. margin-bottom: 5rpx;
  190. }
  191. .desc-line.asset-count {
  192. font-size: 32rpx;
  193. color: #FFC800;
  194. }
  195. .slide-img {
  196. border-radius: 5px;
  197. width: 560rpx;
  198. height: 264rpx;
  199. }
  200. /*.zichan .third-line {
  201. display: flex;
  202. flex-direction: row;
  203. justify-content: space-between;
  204. font-size: 27rpx;
  205. margin-left: 20rpx;
  206. margin-top: 20rpx;
  207. margin-bottom: 20rpx;
  208. }*/
  209. /* 绑定手机号的两个form */
  210. .login-title {
  211. margin: 20rpx 0 35rpx;
  212. text-align: center;
  213. font-size: 30rpx;
  214. }
  215. .login {
  216. font-size: 32rpx;
  217. display: flex;
  218. flex-direction: column;
  219. align-items: center;
  220. }
  221. .login .first-line {
  222. height: 80rpx;
  223. border: 1rpx solid rgb(217, 217, 217);
  224. border-radius: 5px;
  225. width: 600rpx;
  226. margin-bottom: 20rpx;
  227. }
  228. .login .first-line input {
  229. padding-left: 20rpx;
  230. height: 80rpx;
  231. }
  232. .login .second-line {
  233. height: 80rpx;
  234. display: flex;
  235. width: 600rpx;
  236. margin-bottom: 50rpx;
  237. }
  238. .login .second-line input {
  239. height: 80rpx;
  240. width: 350rpx;
  241. margin-right: 20rpx;
  242. border: 1rpx solid rgb(217, 217, 217);
  243. padding-left: 20rpx;
  244. border-radius: 5px;
  245. }
  246. .login .second-line button {
  247. text-align: center;
  248. height: 84rpx;
  249. line-height: 84rpx;
  250. width: 250rpx;
  251. font-size: 30rpx;
  252. background-color: #FFC800;
  253. }
  254. .login .password-second-line {
  255. height: 80rpx;
  256. display: flex;
  257. width: 600rpx;
  258. margin-bottom: 50rpx;
  259. }
  260. .login .password-second-line input {
  261. height: 80rpx;
  262. width: 600rpx;
  263. border: 1rpx solid rgb(217, 217, 217);
  264. padding-left: 20rpx;
  265. border-radius: 5px;
  266. }
  267. .third-line {
  268. margin-left: auto;
  269. margin-right: auto;
  270. width: 600rpx;
  271. }
  272. .third-line button {
  273. height: 80rpx;
  274. font-size: 32rpx;
  275. background-color: #FFC800;
  276. }
  277. .login-type {
  278. width: 600rpx;
  279. margin: 60rpx auto 0 auto;
  280. padding: 20rpx 0 20rpx;
  281. font-size: 32rpx;
  282. text-align: right;
  283. text-decoration: underline;
  284. }
  285. /*************/
  286. .profile-button-container {
  287. display: flex;
  288. flex-wrap: wrap;
  289. margin-top: 10rpx;
  290. margin-bottom: 10rpx;
  291. }
  292. .profile-button {
  293. display: flex;
  294. flex-direction: column;
  295. align-items: center;
  296. justify-content: center;
  297. width: 188rpx;
  298. height: 130rpx;
  299. }
  300. .profile-button image {
  301. width: 36rpx;
  302. height: 36rpx;
  303. }
  304. .profile-button text {
  305. font-size: 25rpx;
  306. }
  307. </style>