login.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. }).then(res => {
  120. if(res.Ret === 200) {
  121. this.$refs.uCode.start();
  122. }
  123. })
  124. }else {
  125. !this.email && this.$util.toast('请先输入邮箱');
  126. this.email && User.getEmailCode({
  127. Email:this.email
  128. }).then(res => {
  129. if(res.Ret === 200) {
  130. this.$refs.uCode.start();
  131. }
  132. })
  133. }
  134. }
  135. },
  136. /* 绑定 */
  137. bindHandle() {
  138. let params;
  139. if(this.bind_type === 1) {
  140. params = {
  141. LoginType: 1,
  142. Mobile: this.phoneNum,
  143. CountryCode:this.countryCode
  144. }
  145. User.Bind(params).then(res => {
  146. if(res.Ret === 200) {
  147. let token = res.Data.Authorization;
  148. this.$db.set('access_token',token)
  149. uni.navigateBack({
  150. delta:1
  151. })
  152. }
  153. })
  154. }else {
  155. if(this.email && this.codeNum && this.checked) {
  156. params = {
  157. Email: this.email,
  158. LoginType: 2,
  159. VCode: this.codeNum
  160. }
  161. User.Bind(params).then(res => {
  162. if(res.Ret === 200) {
  163. let token = res.Data.Authorization;
  164. this.$db.set('access_token',token)
  165. uni.navigateBack({
  166. delta:1
  167. })
  168. }
  169. })
  170. } else {
  171. this.$util.toast(!this.checked?'请先勾选用户服务协议':!this.email?'请输入邮箱地址':'请输入验证码')
  172. }
  173. }
  174. },
  175. lookArgeement() {
  176. uni.navigateTo({
  177. url:'/pages/agreement/agreement'
  178. })
  179. },
  180. /* 绑定手机号 */
  181. bindPhoneHandle() {
  182. if(this.phoneIpt && this.phone_code && this.checked) {
  183. let params = {
  184. Mobile: this.phoneIpt,
  185. LoginType: 3,
  186. VCode: this.phone_code,
  187. CountryCode:this.countryCode
  188. }
  189. User.Bind(params).then(res => {
  190. if(res.Ret === 200) {
  191. let token = res.Data.Authorization;
  192. this.$db.set('access_token',token)
  193. uni.navigateBack({
  194. delta:1
  195. })
  196. }
  197. })
  198. } else {
  199. this.$util.toast(!this.checked?'请先勾选用户服务协议':!this.phoneIpt?'请输入手机号':'请输入验证码')
  200. }
  201. },
  202. areacode(num){
  203. this.showCountryCode= '+' + num
  204. this.countryCode=num
  205. this.isAreaCode=false
  206. },
  207. cancel(){
  208. this.isAreaCode=false
  209. }
  210. },
  211. onLoad() {
  212. /* 校验session */
  213. uni.checkSession({
  214. success: (res) => {
  215. if(res.errMsg != 'checkSession:ok') {
  216. uni.login({
  217. success: result=> {
  218. User.wechatLog({
  219. Code:result.code
  220. }).then(res => {
  221. let token = res.Data.Authorization;
  222. this.$db.set('access_token',token);
  223. })
  224. }
  225. });
  226. }
  227. },
  228. fail: (err) => {
  229. uni.login({
  230. success: result=> {
  231. User.wechatLog({
  232. Code:result.code
  233. }).then(res => {
  234. let token = res.Data.Authorization;
  235. this.$db.set('access_token',token);
  236. })
  237. }
  238. });
  239. }
  240. })
  241. },
  242. onShow() {
  243. // #ifdef MP-WEIXIN
  244. uni.hideHomeButton()
  245. // #endif
  246. }
  247. }
  248. </script>
  249. <style lang="scss">
  250. .login-container {
  251. color: #333;
  252. .bind-tab {
  253. padding: 30rpx 34rpx 0;
  254. display: flex;
  255. align-items: center;
  256. font-size: 34rpx;
  257. .tab {
  258. margin-right: 60rpx;
  259. padding-bottom: 8rpx;
  260. &.act-tab {
  261. border-bottom: 4rpx solid #07C160;
  262. }
  263. }
  264. }
  265. .bind-cont {
  266. .tel-bind {
  267. padding: 40rpx 0 60rpx;
  268. }
  269. .infobutton {
  270. width: 368rpx;
  271. height: 80rpx;
  272. line-height: 80rpx;
  273. background-color: #07C160;
  274. color: #fff;
  275. margin: 40rpx auto 0;
  276. }
  277. .email-bind {
  278. padding: 40rpx 0 60px;
  279. }
  280. .ipt-item {
  281. padding: 33rpx 32rpx;
  282. border-bottom: 1rpx solid #E5E5E5;
  283. display: flex;
  284. align-items: center;
  285. font-size: 34rpx;
  286. position: relative;
  287. .item-label {
  288. text-align: justify;
  289. text-align-last: justify;
  290. display: inline-block;
  291. width: 106rpx;
  292. margin-right: 40rpx;
  293. }
  294. .ipt {
  295. width: 500rpx;
  296. font-size: 32rpx;
  297. color: #666;
  298. }
  299. .code-btn {
  300. position: absolute;
  301. right: 34rpx;
  302. background-color: #fff;
  303. font-size: 28rpx;
  304. color: #07C160;
  305. }
  306. }
  307. .bind-btn {
  308. margin-top: 140rpx;
  309. }
  310. .bind-bot {
  311. display: flex;
  312. align-items: center;
  313. font-size: 24rpx;
  314. padding: 0 34rpx;
  315. margin-top: 30rpx;
  316. .check-sty {
  317. transform:scale(0.7)
  318. }
  319. .tip {
  320. text {
  321. display: inline;
  322. color: #07C160;
  323. }
  324. }
  325. }
  326. }
  327. .item-iphone {
  328. display: flex !important;
  329. justify-content: space-between !important;
  330. align-items: center !important;
  331. width: 118rpx !important;
  332. margin-right: 26rpx !important;
  333. }
  334. }
  335. </style>