login.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <view class="container login-container">
  3. <view class="bind-tab">
  4. <text :class="['tab',{'act-tab':bind_type === 1}]" @click="toggleTab(1)">手机号</text>
  5. <text :class="['tab',{'act-tab':bind_type === 2}]" @click="toggleTab(2)">邮箱</text>
  6. </view>
  7. <view class="bind-cont">
  8. <view class="tel-bind" v-if="bind_type === 1">
  9. <view class="ipt-item">
  10. <label class="item-label item-iphone" @click="isAreaCode=true">{{showCountryCode}} <u-icon :name="isAreaCode?'arrow-up':'arrow-down'" color="#B2B2B2" size="28"></u-icon></label>
  11. <input type="number" v-model="phoneIpt" class="ipt" placeholder="请输入手机号" style="width: 300rpx;">
  12. <button open-type="getPhoneNumber" value="用户授权" @getphonenumber="getPhoneNumber" class='code-btn'>微信手机号绑定</button>
  13. </view>
  14. <view class="ipt-item">
  15. <label class="item-label">验证码</label>
  16. <input type="number" v-model="phone_code" class="ipt" placeholder="请输入4位验证码" maxlength="6" style="width: 300rpx;">
  17. <u-verification-code :seconds="seconds" ref="uCode"
  18. @change="codeChange"></u-verification-code>
  19. <button @click="getCode" class="code-btn">{{tips}}</button>
  20. </view>
  21. <view class="bind-bot">
  22. <u-checkbox v-model="checked" :disabled="false" active-color="#07C160" size="34"></u-checkbox>
  23. <view class="tip">我已阅读并同意<text @click="lookArgeement">《用户服务协议》</text> </view>
  24. </view>
  25. <button @click="bindPhoneHandle" class='infobutton bind-btn'>提交</button>
  26. <!-- <button v-if="checked" open-type="getPhoneNumber" value="用户授权" @getphonenumber="getPhoneNumber" class='infobutton plain-style'>微信手机号绑定</button>
  27. <button v-else value="用户授权"class='infobutton plain-style' @click="$util.toast('请先勾选用户服务协议')">微信手机号绑定</button> -->
  28. </view>
  29. <view class="email-bind" v-else>
  30. <view class="ipt-item">
  31. <label class="item-label">邮箱</label>
  32. <input type="text" v-model="email" class="ipt" placeholder="请输入邮箱地址">
  33. </view>
  34. <view class="ipt-item">
  35. <label class="item-label">验证码</label>
  36. <input type="number" v-model="codeNum" class="ipt" placeholder="请输入4位验证码" maxlength="6" style="width: 300rpx;">
  37. <u-verification-code :seconds="seconds" ref="uCode"
  38. @change="codeChange"></u-verification-code>
  39. <button @click="getCode" class="code-btn">{{tips}}</button>
  40. </view>
  41. <view class="bind-bot">
  42. <u-checkbox v-model="checked" :disabled="false" active-color="#07C160" size="34"></u-checkbox>
  43. <view class="tip">我已阅读并同意<text @click="lookArgeement">《用户服务协议》</text> </view>
  44. </view>
  45. <button @click="bindHandle" class='infobutton bind-btn'>提交</button>
  46. </view>
  47. </view>
  48. <view class="select-box">
  49. <u-popup v-model="isAreaCode" mode="bottom" @close="cancel">
  50. <view class="box" style="color: #333333;font-size: 28rpxrpx;">请选择您的国际区号</view>
  51. <view class="box" style="color: #2C83FF;" @click="areacode('86')">大陆+86</view>
  52. <view class="box" style="color: #2C83FF;" @click="areacode('852')">香港+852</view>
  53. <view class="box" style="color: #2C83FF;" @click="areacode('886')">台湾+886</view>
  54. <view class="box" style="color: #2C83FF;" @click="areacode('1')">美国+1</view>
  55. <view class="box" style="color: #2C83FF;" @click="areacode('65')">新加坡+65</view>
  56. <view class="box box-bottom" style="color: #A9AFB8;" @click="cancel">取消</view>
  57. </u-popup>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { User } from '@/config/api.js';
  63. export default {
  64. data() {
  65. return {
  66. bind_type:1,//绑定方式
  67. checked:false,
  68. isArgee:false,
  69. seconds:60,
  70. tips:'获取验证码',
  71. email:'',//邮箱
  72. phoneNum:'',//手机号,
  73. codeNum:'',//验证码
  74. phoneIpt:'',
  75. phone_code:'',
  76. showCountryCode:'+86',
  77. countryCode:'86',//区号
  78. isAreaCode: false,
  79. };
  80. },
  81. methods:{
  82. /* 切换方式 */
  83. toggleTab(val) {
  84. this.email = ''
  85. this.phoneNum = ''
  86. this.codeNum = ''
  87. this.bind_type = val;
  88. this.phoneIpt = '';
  89. this.phone_code = '';
  90. this.checked = false;
  91. },
  92. /* 授权获取手机号 */
  93. getPhoneNumber(e) {
  94. //console.log(e)
  95. if(e.detail.errMsg == 'getPhoneNumber:ok') { // 点击了允许
  96. User.getPhoneNum({
  97. EncryptedData: e.detail.encryptedData,
  98. Iv: e.detail.iv
  99. }).then(res => {
  100. if(res.Ret === 200) {
  101. this.phoneNum = res.Data.PurePhoneNumber;
  102. this.countryCode=res.Data.CountryCode
  103. this.phoneIpt=res.Data.PhoneNumber;
  104. this.bindHandle()
  105. }
  106. })
  107. }
  108. },
  109. codeChange(text) {
  110. this.tips = text;
  111. },
  112. /* 获取邮箱验证码 */
  113. getCode() {
  114. if(this.$refs.uCode.canGetCode) {
  115. if(this.bind_type === 1) {
  116. !this.phoneIpt && this.$util.toast('请先输入手机号');
  117. this.phoneIpt && User.getPhoneCode({
  118. Mobile:this.phoneIpt,
  119. AreaNum:this.countryCode
  120. }).then(res => {
  121. if(res.Ret === 200) {
  122. this.$refs.uCode.start();
  123. }
  124. })
  125. }else {
  126. !this.email && this.$util.toast('请先输入邮箱');
  127. this.email && User.getEmailCode({
  128. Email:this.email
  129. }).then(res => {
  130. if(res.Ret === 200) {
  131. this.$refs.uCode.start();
  132. }
  133. })
  134. }
  135. }
  136. },
  137. /* 绑定 */
  138. bindHandle() {
  139. let params;
  140. if(this.bind_type === 1) {
  141. params = {
  142. LoginType: 1,
  143. Mobile: this.phoneNum,
  144. CountryCode:this.countryCode
  145. }
  146. User.Bind(params).then(res => {
  147. if(res.Ret === 200) {
  148. let token = res.Data.Authorization;
  149. this.$db.set('access_token',token)
  150. uni.navigateBack({
  151. delta:1
  152. })
  153. }
  154. })
  155. }else {
  156. if(this.email && this.codeNum && this.checked) {
  157. params = {
  158. Email: this.email,
  159. LoginType: 2,
  160. VCode: this.codeNum
  161. }
  162. User.Bind(params).then(res => {
  163. if(res.Ret === 200) {
  164. let token = res.Data.Authorization;
  165. this.$db.set('access_token',token)
  166. uni.navigateBack({
  167. delta:1
  168. })
  169. }
  170. })
  171. } else {
  172. this.$util.toast(!this.checked?'请先勾选用户服务协议':!this.email?'请输入邮箱地址':'请输入验证码')
  173. }
  174. }
  175. },
  176. lookArgeement() {
  177. uni.navigateTo({
  178. url:'/pages/agreement/agreement'
  179. })
  180. },
  181. /* 绑定手机号 */
  182. bindPhoneHandle() {
  183. if(this.phoneIpt && this.phone_code && this.checked) {
  184. let params = {
  185. Mobile: this.phoneIpt,
  186. LoginType: 3,
  187. VCode: this.phone_code,
  188. CountryCode:this.countryCode
  189. }
  190. User.Bind(params).then(res => {
  191. if(res.Ret === 200) {
  192. let token = res.Data.Authorization;
  193. this.$db.set('access_token',token)
  194. uni.navigateBack({
  195. delta:1
  196. })
  197. }
  198. })
  199. } else {
  200. this.$util.toast(!this.checked?'请先勾选用户服务协议':!this.phoneIpt?'请输入手机号':'请输入验证码')
  201. }
  202. },
  203. areacode(num){
  204. this.showCountryCode= '+' + num
  205. this.countryCode=num
  206. this.isAreaCode=false
  207. },
  208. cancel(){
  209. this.isAreaCode=false
  210. }
  211. },
  212. onLoad() {
  213. /* 校验session */
  214. uni.checkSession({
  215. success: (res) => {
  216. if(res.errMsg != 'checkSession:ok') {
  217. uni.login({
  218. success: result=> {
  219. User.wechatLog({
  220. Code:result.code
  221. }).then(res => {
  222. let token = res.Data.Authorization;
  223. this.$db.set('access_token',token);
  224. })
  225. }
  226. });
  227. }
  228. },
  229. fail: (err) => {
  230. uni.login({
  231. success: result=> {
  232. User.wechatLog({
  233. Code:result.code
  234. }).then(res => {
  235. let token = res.Data.Authorization;
  236. this.$db.set('access_token',token);
  237. })
  238. }
  239. });
  240. }
  241. })
  242. },
  243. onShow() {
  244. // #ifdef MP-WEIXIN
  245. uni.hideHomeButton()
  246. // #endif
  247. }
  248. }
  249. </script>
  250. <style lang="scss">
  251. .login-container {
  252. color: #333;
  253. .bind-tab {
  254. padding: 30rpx 34rpx 0;
  255. display: flex;
  256. align-items: center;
  257. font-size: 34rpx;
  258. .tab {
  259. margin-right: 60rpx;
  260. padding-bottom: 8rpx;
  261. &.act-tab {
  262. border-bottom: 4rpx solid #07C160;
  263. }
  264. }
  265. }
  266. .bind-cont {
  267. .tel-bind {
  268. padding: 40rpx 0 60rpx;
  269. }
  270. .infobutton {
  271. width: 368rpx;
  272. height: 80rpx;
  273. line-height: 80rpx;
  274. background-color: #07C160;
  275. color: #fff;
  276. margin: 40rpx auto 0;
  277. }
  278. .email-bind {
  279. padding: 40rpx 0 60px;
  280. }
  281. .ipt-item {
  282. padding: 33rpx 32rpx;
  283. border-bottom: 1rpx solid #E5E5E5;
  284. display: flex;
  285. align-items: center;
  286. font-size: 34rpx;
  287. position: relative;
  288. .item-label {
  289. text-align: justify;
  290. text-align-last: justify;
  291. display: inline-block;
  292. width: 106rpx;
  293. margin-right: 40rpx;
  294. }
  295. .ipt {
  296. width: 500rpx;
  297. font-size: 32rpx;
  298. color: #666;
  299. }
  300. .code-btn {
  301. position: absolute;
  302. right: 34rpx;
  303. background-color: #fff;
  304. font-size: 28rpx;
  305. color: #07C160;
  306. }
  307. }
  308. .bind-btn {
  309. margin-top: 140rpx;
  310. }
  311. .bind-bot {
  312. display: flex;
  313. align-items: center;
  314. font-size: 24rpx;
  315. padding: 0 34rpx;
  316. margin-top: 30rpx;
  317. .check-sty {
  318. transform:scale(0.7)
  319. }
  320. .tip {
  321. text {
  322. display: inline;
  323. color: #07C160;
  324. }
  325. }
  326. }
  327. }
  328. .item-iphone {
  329. display: flex !important;
  330. justify-content: space-between !important;
  331. align-items: center !important;
  332. width: 118rpx !important;
  333. margin-right: 26rpx !important;
  334. }
  335. }
  336. </style>