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