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. 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. //console.log(e)
  92. if (e.detail.errMsg == "getPhoneNumber:ok") {
  93. // 点击了允许
  94. User.getPhoneNum({
  95. EncryptedData: e.detail.encryptedData,
  96. Iv: e.detail.iv,
  97. }).then((res) => {
  98. if (res.Ret === 200) {
  99. this.phoneNum = res.Data.PurePhoneNumber;
  100. this.countryCode = res.Data.CountryCode;
  101. this.phoneIpt = res.Data.PhoneNumber;
  102. this.bindHandle();
  103. }
  104. });
  105. }
  106. },
  107. codeChange(text) {
  108. this.tips = text;
  109. },
  110. /* 获取邮箱验证码 */
  111. getCode() {
  112. if (this.$refs.uCode.canGetCode) {
  113. if (this.bind_type === 1) {
  114. !this.phoneIpt && this.$util.toast("请先输入手机号");
  115. this.phoneIpt &&
  116. User.getPhoneCode({
  117. Mobile: this.phoneIpt,
  118. AreaNum: this.countryCode,
  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 &&
  127. 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. ShareUserCode: this.scene,
  146. };
  147. User.Bind(params).then((res) => {
  148. if (res.Ret === 200) {
  149. let token = res.Data.Authorization;
  150. this.$db.set("access_token", token);
  151. uni.navigateBack({
  152. delta: 1,
  153. fail: (err) => {
  154. uni.switchTab({
  155. url: "/pages/index/index",
  156. });
  157. },
  158. });
  159. }
  160. });
  161. } else {
  162. if (this.email && this.codeNum && this.checked) {
  163. params = {
  164. Email: this.email,
  165. LoginType: 2,
  166. VCode: this.codeNum,
  167. ShareUserCode: this.scene,
  168. };
  169. User.Bind(params).then((res) => {
  170. if (res.Ret === 200) {
  171. let token = res.Data.Authorization;
  172. this.$db.set("access_token", token);
  173. uni.navigateBack({
  174. delta: 1,
  175. fail: (err) => {
  176. uni.switchTab({
  177. url: "/pages/index/index",
  178. });
  179. },
  180. });
  181. }
  182. });
  183. } else {
  184. this.$util.toast(!this.checked ? "请先勾选用户服务协议" : !this.email ? "请输入邮箱地址" : "请输入验证码");
  185. }
  186. }
  187. },
  188. lookArgeement() {
  189. uni.navigateTo({
  190. url: "/pageMy/agreement/agreement",
  191. });
  192. },
  193. /* 绑定手机号 */
  194. bindPhoneHandle() {
  195. if (this.phoneIpt && this.phone_code && this.checked) {
  196. let params = {
  197. Mobile: this.phoneIpt,
  198. LoginType: 3,
  199. VCode: this.phone_code,
  200. CountryCode: this.countryCode,
  201. ShareUserCode: this.scene,
  202. };
  203. User.Bind(params).then((res) => {
  204. if (res.Ret === 200) {
  205. let token = res.Data.Authorization;
  206. this.$db.set("access_token", token);
  207. uni.navigateBack({
  208. delta: 1,
  209. fail: (err) => {
  210. uni.switchTab({
  211. url: "/pages/index/index",
  212. });
  213. },
  214. });
  215. }
  216. });
  217. } else {
  218. this.$util.toast(!this.checked ? "请先勾选用户服务协议" : !this.phoneIpt ? "请输入手机号" : "请输入验证码");
  219. }
  220. },
  221. areacode(num) {
  222. this.showCountryCode = "+" + num;
  223. this.countryCode = num;
  224. this.isAreaCode = false;
  225. },
  226. cancel() {
  227. this.isAreaCode = false;
  228. },
  229. },
  230. onLoad(options) {
  231. /* 校验session */
  232. uni.checkSession({
  233. success: (res) => {
  234. if (res.errMsg != "checkSession:ok") {
  235. uni.login({
  236. success: (result) => {
  237. User.wechatLog({
  238. Code: result.code,
  239. }).then((res) => {
  240. let token = res.Data.Authorization;
  241. this.$db.set("access_token", token);
  242. });
  243. },
  244. });
  245. }
  246. },
  247. fail: (err) => {
  248. uni.login({
  249. success: (result) => {
  250. User.wechatLog({
  251. Code: result.code,
  252. }).then((res) => {
  253. let token = res.Data.Authorization;
  254. this.$db.set("access_token", token);
  255. });
  256. },
  257. });
  258. },
  259. });
  260. this.scene = options.scene || "";
  261. },
  262. onShow() {
  263. // #ifdef MP-WEIXIN
  264. uni.hideHomeButton();
  265. // #endif
  266. },
  267. };
  268. </script>
  269. <style lang="scss">
  270. .login-container {
  271. color: #333;
  272. .bind-tab {
  273. padding: 30rpx 34rpx 0;
  274. display: flex;
  275. align-items: center;
  276. font-size: 34rpx;
  277. .tab {
  278. margin-right: 60rpx;
  279. padding-bottom: 8rpx;
  280. &.act-tab {
  281. border-bottom: 4rpx solid #07c160;
  282. }
  283. }
  284. }
  285. .bind-cont {
  286. .tel-bind {
  287. padding: 40rpx 0 60rpx;
  288. }
  289. .infobutton {
  290. width: 368rpx;
  291. height: 80rpx;
  292. line-height: 80rpx;
  293. background-color: #07c160;
  294. color: #fff;
  295. margin: 40rpx auto 0;
  296. }
  297. .email-bind {
  298. padding: 40rpx 0 60px;
  299. }
  300. .ipt-item {
  301. padding: 33rpx 32rpx;
  302. border-bottom: 1rpx solid #e5e5e5;
  303. display: flex;
  304. align-items: center;
  305. font-size: 34rpx;
  306. position: relative;
  307. .item-label {
  308. text-align: justify;
  309. text-align-last: justify;
  310. display: inline-block;
  311. width: 106rpx;
  312. margin-right: 40rpx;
  313. }
  314. .ipt {
  315. width: 500rpx;
  316. font-size: 32rpx;
  317. color: #666;
  318. }
  319. .code-btn {
  320. position: absolute;
  321. right: 34rpx;
  322. background-color: #fff;
  323. font-size: 28rpx;
  324. color: #07c160;
  325. }
  326. }
  327. .bind-btn {
  328. margin-top: 140rpx;
  329. }
  330. .bind-bot {
  331. display: flex;
  332. align-items: center;
  333. font-size: 24rpx;
  334. padding: 0 34rpx;
  335. margin-top: 30rpx;
  336. .check-sty {
  337. transform: scale(0.7);
  338. }
  339. .tip {
  340. text {
  341. display: inline;
  342. color: #07c160;
  343. }
  344. }
  345. }
  346. }
  347. .item-iphone {
  348. display: flex !important;
  349. justify-content: space-between !important;
  350. align-items: center !important;
  351. width: 118rpx !important;
  352. margin-right: 26rpx !important;
  353. }
  354. }
  355. </style>