login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. seconds: 60,
  64. tips: "获取验证码",
  65. email: "", //邮箱
  66. phoneNum: "", //手机号,
  67. codeNum: "", //验证码
  68. phoneIpt: "",
  69. phone_code: "",
  70. showCountryCode: "+86",
  71. countryCode: "86", //区号
  72. scene: "", //分享人的分享码
  73. isAreaCode: false, //选择区号
  74. checked: false, //勾选了同意
  75. };
  76. },
  77. methods: {
  78. /* 切换方式 */
  79. toggleTab(val) {
  80. this.email = "";
  81. this.phoneNum = "";
  82. this.codeNum = "";
  83. this.bind_type = val;
  84. this.phoneIpt = "";
  85. this.phone_code = "";
  86. this.checked = false;
  87. },
  88. /* 授权获取手机号 */
  89. getPhoneNumber(e) {
  90. if (e.detail.errMsg == "getPhoneNumber:ok") {
  91. // 点击了允许
  92. User.getPhoneNum({
  93. EncryptedData: e.detail.encryptedData,
  94. Iv: e.detail.iv,
  95. }).then((res) => {
  96. if (res.Ret === 200) {
  97. this.phoneNum = res.Data.PurePhoneNumber;
  98. this.countryCode = res.Data.CountryCode;
  99. this.phoneIpt = res.Data.PhoneNumber;
  100. this.bindHandle();
  101. }
  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. // 查看用户协议
  162. lookArgeement() {
  163. uni.navigateTo({
  164. url: "/pageMy/agreement/agreement",
  165. });
  166. },
  167. /* 绑定手机号 */
  168. bindPhoneHandle() {
  169. if (this.phoneIpt && this.phone_code && this.checked) {
  170. let params = {
  171. Mobile: this.phoneIpt,
  172. LoginType: 3,
  173. VCode: this.phone_code,
  174. CountryCode: this.countryCode,
  175. ShareUserCode: this.scene,
  176. };
  177. this.bindLogin(params);
  178. } else {
  179. this.$util.toast(!this.checked ? "请先勾选用户服务协议" : !this.phoneIpt ? "请输入手机号" : "请输入验证码");
  180. }
  181. },
  182. //绑定登陆
  183. bindLogin(params) {
  184. User.Bind(params).then((res) => {
  185. if (res.Ret === 200) {
  186. let token = res.Data.Authorization;
  187. this.$db.set("access_token", token);
  188. if (res.Data.IsPotential && this.scene) {
  189. uni.reLaunch({
  190. url: "/pageMy/transitionPages/transitionPages",
  191. });
  192. } else {
  193. let pages = getCurrentPages();
  194. let prevPage = pages[pages.length - 2];
  195. let path = prevPage ? prevPage.$page.fullPath : "";
  196. console.log(pages, prevPage, path, "----");
  197. if (path.includes("/pages/index/index")) {
  198. uni.$emit("updateAudioVideo");
  199. }
  200. uni.navigateBack({
  201. delta: 1,
  202. fail: (err) => {
  203. uni.switchTab({
  204. url: "/pages/index/index",
  205. });
  206. },
  207. });
  208. }
  209. }
  210. });
  211. },
  212. // 选择了地区的区号
  213. areacode(num) {
  214. this.showCountryCode = "+" + num;
  215. this.countryCode = num;
  216. this.isAreaCode = false;
  217. },
  218. // 选择区号的取消
  219. cancel() {
  220. this.isAreaCode = false;
  221. },
  222. },
  223. onLoad(options) {
  224. /* 校验session */
  225. uni.checkSession({
  226. success: (res) => {
  227. if (res.errMsg != "checkSession:ok") {
  228. uni.login({
  229. success: (result) => {
  230. User.wechatLog({
  231. Code: result.code,
  232. }).then((res) => {
  233. let token = res.Data.Authorization;
  234. this.$db.set("access_token", token);
  235. });
  236. },
  237. });
  238. }
  239. },
  240. fail: (err) => {
  241. uni.login({
  242. success: (result) => {
  243. User.wechatLog({
  244. Code: result.code,
  245. }).then((res) => {
  246. let token = res.Data.Authorization;
  247. this.$db.set("access_token", token);
  248. });
  249. },
  250. });
  251. },
  252. });
  253. this.scene = options.scene || "";
  254. },
  255. onShow() {
  256. // #ifdef MP-WEIXIN
  257. uni.hideHomeButton();
  258. // #endif
  259. },
  260. };
  261. </script>
  262. <style lang="scss">
  263. .login-container {
  264. color: #333;
  265. .bind-tab {
  266. padding: 30rpx 34rpx 0;
  267. display: flex;
  268. align-items: center;
  269. font-size: 34rpx;
  270. .tab {
  271. margin-right: 60rpx;
  272. padding-bottom: 8rpx;
  273. &.act-tab {
  274. border-bottom: 4rpx solid #07c160;
  275. }
  276. }
  277. }
  278. .bind-cont {
  279. .tel-bind {
  280. padding: 40rpx 0 60rpx;
  281. }
  282. .infobutton {
  283. width: 368rpx;
  284. height: 80rpx;
  285. line-height: 80rpx;
  286. background-color: #07c160;
  287. color: #fff;
  288. margin: 40rpx auto 0;
  289. }
  290. .email-bind {
  291. padding: 40rpx 0 60px;
  292. }
  293. .ipt-item {
  294. padding: 33rpx 32rpx;
  295. border-bottom: 1rpx solid #e5e5e5;
  296. display: flex;
  297. align-items: center;
  298. font-size: 34rpx;
  299. position: relative;
  300. .item-label {
  301. text-align: justify;
  302. text-align-last: justify;
  303. display: inline-block;
  304. width: 106rpx;
  305. margin-right: 40rpx;
  306. }
  307. .ipt {
  308. width: 500rpx;
  309. font-size: 32rpx;
  310. color: #666;
  311. }
  312. .code-btn {
  313. position: absolute;
  314. right: 34rpx;
  315. background-color: #fff;
  316. font-size: 28rpx;
  317. color: #07c160;
  318. }
  319. }
  320. .bind-btn {
  321. margin-top: 140rpx;
  322. }
  323. .bind-bot {
  324. display: flex;
  325. align-items: center;
  326. font-size: 24rpx;
  327. padding: 0 34rpx;
  328. margin-top: 30rpx;
  329. .check-sty {
  330. transform: scale(0.7);
  331. }
  332. .tip {
  333. text {
  334. display: inline;
  335. color: #07c160;
  336. }
  337. }
  338. }
  339. }
  340. .item-iphone {
  341. display: flex !important;
  342. justify-content: space-between !important;
  343. align-items: center !important;
  344. width: 118rpx !important;
  345. margin-right: 26rpx !important;
  346. }
  347. }
  348. </style>