otherLogin.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <view
  3. class="container-mine"
  4. :style="{
  5. backgroundImage: `url(${$handleImageUrl(
  6. '/login/bg1.png'
  7. )}) no-repeat 0 -70rpx`,
  8. }"
  9. >
  10. <uv-navbar
  11. title="注册/登录"
  12. titleStyle="font-weight: 700;"
  13. placeholder
  14. @leftClick="
  15. () => {
  16. uni.navigateBack();
  17. }
  18. "
  19. bgColor="transparent"
  20. ></uv-navbar>
  21. <view class="welcome">
  22. <view>您好</view>
  23. <view>欢迎登录商城!</view>
  24. </view>
  25. <view class="formBox">
  26. <view class="title">手机号登录</view>
  27. <view class="tig">首次登录将为您注册</view>
  28. <view class="phoneBox">
  29. <view class="phoneBox_l">
  30. <image :src="$handleImageUrl('/login/icon1.png')" mode=""></image>
  31. 手机号
  32. </view>
  33. <view class="phoneBox_r">
  34. <input
  35. v-model="mobile"
  36. type="number"
  37. maxlength="11"
  38. placeholder="请输入"
  39. placeholder-class="placeholder-class"
  40. />
  41. </view>
  42. </view>
  43. <view class="btnBox">
  44. <uv-button type="primary" hover-class="hoverClass" @click="login"
  45. >立即登录</uv-button
  46. >
  47. </view>
  48. <view class="agreementCls">
  49. <uv-checkbox-group size="26rpx" v-model="checked">
  50. <uv-checkbox
  51. shape="square"
  52. size="30rpx"
  53. active-color="#0090FF"
  54. :name="1"
  55. >
  56. 我已阅读同意
  57. </uv-checkbox>
  58. </uv-checkbox-group>
  59. <text @click="goAgreement('user_protocol')">《服务协议》</text>和<text
  60. @click="goAgreement('privacy_protocol')"
  61. >《隐私政策》</text
  62. >
  63. </view>
  64. <!-- <view class="loginBox">
  65. <uv-divider
  66. half-width="50"
  67. textColor="##1A1A1A"
  68. text="更多登录方式"
  69. ></uv-divider>
  70. <view class="loginBox_b">
  71. <view
  72. @click="wxLogin(0)"
  73. class="wxCls"
  74. v-if="isInstallWx || platform != 'ios'"
  75. >
  76. <text class="iconfont">&#xe6ea;</text>
  77. </view>
  78. <view
  79. @click="alipayLogin(1)"
  80. v-if="isInstallZfb || platform != 'ios'"
  81. >
  82. <text class="iconfont" style="color: #00aaee">&#xe611;</text>
  83. </view>
  84. <view
  85. class="appleCls"
  86. v-if="osVersion >= 13 && platform == 'ios'"
  87. @click="appleLogin()"
  88. >
  89. <text class="iconfont">&#xe624;</text>
  90. </view>
  91. </view>
  92. </view> -->
  93. </view>
  94. </view>
  95. </template>
  96. <script setup>
  97. import { miniappThirdLogin } from "@/api/login";
  98. import { ref, reactive } from "vue";
  99. import { onLoad } from "@dcloudio/uni-app";
  100. const mobile = ref(""),
  101. checked = ref(false),
  102. osVersion = ref(""),
  103. platform = ref(""),
  104. isInstallWx = ref(true), //是否安装微信
  105. isInstallZfb = ref(true), //是否安装支付宝
  106. isOneClickLogin = ref(false);
  107. onLoad(() => {
  108. uni.getSystemInfo({
  109. success: (res) => {
  110. osVersion.value = res.osVersion.split(".")[0];
  111. platform.value = res.platform;
  112. },
  113. });
  114. // #ifdef APP-PLUS
  115. isInstallWx.value = plus.runtime.isApplicationExist({
  116. pname: "com.tencent.mm",
  117. action: "weixin://",
  118. });
  119. isInstallZfb.value = plus.runtime.isApplicationExist({
  120. pname: "com.eg.android.AlipayGphone",
  121. action: "alipay://",
  122. });
  123. plus.push.getClientInfoAsync((info) => {
  124. let cid = info["clientid"];
  125. uni.setStorageSync("cid", cid);
  126. });
  127. // #endif
  128. });
  129. const login = () => {
  130. if (!mobile.value) {
  131. return uni.$uv.toast("请输入手机号");
  132. } else if (!uni.$uv.test.mobile(mobile.value)) {
  133. return uni.$uv.toast("请输入正确手机号");
  134. } else if (!checked.value) {
  135. return uni.$uv.toast("请阅读并同意相关协议");
  136. }
  137. uni.navigateTo({
  138. url: "/pages/login/code?mobile=" + mobile.value,
  139. });
  140. };
  141. const goAgreement = (val) => {
  142. uni.navigateTo({
  143. url: "/pages/protocol/index?code=" + val,
  144. });
  145. };
  146. // 微信登录
  147. const wxLogin = (thirdType) => {
  148. if (!checked.value) {
  149. return uni.$uv.toast("请阅读并同意相关协议");
  150. }
  151. uni.login({
  152. provider: "weixin",
  153. onlyAuthorize: true, // 微信登录仅请求授权认证
  154. success: (event) => {
  155. const { code } = event;
  156. // 客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  157. let param = {
  158. code: code,
  159. thirdType: thirdType,
  160. };
  161. loginRe(param);
  162. },
  163. fail: (err) => {
  164. console.log(err);
  165. uni.$uv.toast("当前环境不支持微信操作!");
  166. },
  167. });
  168. };
  169. const loginRe = (param) => {
  170. console.log("33333", param);
  171. miniappThirdLogin(param)
  172. .then((res) => {
  173. console.log("222222", res);
  174. if (res.data.isReg) {
  175. uni.showToast({
  176. title: "登录成功!",
  177. icon: "success",
  178. duration: 1500,
  179. });
  180. uni.setStorageSync("apiToken", res.data.token);
  181. } else {
  182. uni.navigateTo({
  183. url:
  184. "/pages/login/bindPhone?identityCode=" +
  185. res.data.identityCode +
  186. "&thirdType=" +
  187. param.thirdType,
  188. });
  189. }
  190. })
  191. .catch((e) => {
  192. console.log("11111111", e);
  193. });
  194. };
  195. // 支付宝登录
  196. const alipayLogin = (thirdType) => {
  197. if (!checked.value) {
  198. return uni.$uv.toast("请阅读并同意相关协议");
  199. }
  200. const AlipayAuth = uni.requireNativePlugin("DHQ-AlipayAuth");
  201. AlipayAuth.login(
  202. {
  203. appId: "2021006116626014", //你在支付宝平台申请的App ID
  204. scheme: "xctUrlSchemes", // 需要传到支付宝SDK的scheme,注意需要在manifest.json-->App其他常用配置-->UrlSchemes中配置Android和iOS的
  205. scope: "auth_user", //默认为auth_user
  206. init: "init", //默认传入init
  207. },
  208. (res) => {
  209. console.log("原生授权返回res", res);
  210. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  211. let code = res.auth_code;
  212. if (code) {
  213. let param = {
  214. code: code,
  215. thirdType: thirdType,
  216. };
  217. this.loginRe(param);
  218. }
  219. }
  220. );
  221. // uni.login({
  222. // "provider": "alipay",
  223. // success: (event) => {
  224. // const {
  225. // code
  226. // } = event
  227. // let param = {
  228. // code: code,
  229. // thirdType: thirdType
  230. // }
  231. // loginRe(param)
  232. // },
  233. // fail: (err) => {
  234. // console.log(err);
  235. // // uni.$uv.toast('当前环境不支持支付宝操作!');
  236. // }
  237. // })
  238. };
  239. // 苹果登录
  240. const appleLogin = () => {
  241. if (!checked.value) {
  242. return uni.$uv.toast("请阅读并同意相关协议");
  243. }
  244. uni.login({
  245. provider: "apple",
  246. success: (event) => {
  247. const { code } = event;
  248. let param = {
  249. code: code,
  250. thirdType: 2,
  251. };
  252. loginRe(param);
  253. },
  254. });
  255. };
  256. </script>
  257. <style scoped>
  258. page {
  259. background-color: #f7f8fa;
  260. }
  261. </style>
  262. <style lang="scss" scoped>
  263. .placeholder-class {
  264. font-size: 28rpx;
  265. color: #cccccc;
  266. }
  267. .container-mine {
  268. // background: url("/static/login/bg1.png") no-repeat 0 -70rpx !important;
  269. background-size: 750rpx 742rpx !important;
  270. padding: 0 25rpx;
  271. .welcome {
  272. font-weight: 700;
  273. color: #303030;
  274. font-size: 42rpx;
  275. margin-top: 90rpx;
  276. }
  277. .formBox {
  278. padding: 50rpx 30rpx;
  279. background: #ffffff;
  280. border-radius: 20rpx;
  281. margin-top: 60rpx;
  282. .title {
  283. font-weight: 700;
  284. color: #303030;
  285. font-size: 40rpx;
  286. text-align: center;
  287. }
  288. .tig {
  289. font-size: 22rpx;
  290. color: #666666;
  291. text-align: center;
  292. }
  293. .phoneBox {
  294. display: flex;
  295. justify-content: space-between;
  296. padding: 60rpx 0 30rpx;
  297. border-bottom: 1rpx solid rgba(204, 204, 204, 0.4);
  298. .phoneBox_l {
  299. font-size: 28rpx;
  300. color: #1a1a1a;
  301. display: flex;
  302. align-items: center;
  303. image {
  304. width: 26rpx;
  305. height: 38rpx;
  306. margin-right: 10rpx;
  307. }
  308. }
  309. .phoneBox_r {
  310. flex: 1;
  311. input {
  312. font-size: 28rpx;
  313. color: #1a1a1a;
  314. text-align: right;
  315. }
  316. }
  317. }
  318. .btnBox {
  319. margin-top: 80rpx;
  320. ::v-deep .uv-button {
  321. height: 90rpx;
  322. font-size: 28rpx;
  323. background: #eb5153;
  324. border-color: #eb5153;
  325. border-radius: 92rpx;
  326. }
  327. }
  328. .agreementCls {
  329. margin: auto;
  330. width: 615rpx;
  331. font-size: 26rpx;
  332. display: flex;
  333. align-items: center;
  334. flex-wrap: wrap;
  335. margin-top: 40rpx;
  336. color: #808080;
  337. ::v-deep .u-checkbox__label {
  338. margin-right: 0rpx;
  339. font-size: 26rpx;
  340. }
  341. ::v-deep .uv-checkbox__icon-wrap--square {
  342. border: 1rpx solid #219eff !important;
  343. }
  344. text {
  345. color: #219eff;
  346. }
  347. ::v-deep .uv-checkbox-group {
  348. flex: none;
  349. }
  350. }
  351. }
  352. .loginBox {
  353. position: absolute;
  354. bottom: 100rpx;
  355. width: 100%;
  356. left: 0;
  357. .uv-divider {
  358. width: 350rpx;
  359. margin: auto;
  360. }
  361. .loginBox_b {
  362. display: flex;
  363. justify-content: center;
  364. margin: auto;
  365. margin-top: 60rpx;
  366. > view {
  367. text-align: center;
  368. margin: 0 30rpx;
  369. text {
  370. font-size: 72rpx;
  371. }
  372. > view {
  373. font-size: 26rpx;
  374. color: #333333;
  375. }
  376. }
  377. .wxCls {
  378. width: 72rpx;
  379. height: 72rpx;
  380. background: #4cbf00;
  381. color: #fff;
  382. border-radius: 50%;
  383. text-align: center;
  384. line-height: 72rpx;
  385. text {
  386. font-size: 52rpx;
  387. }
  388. }
  389. .appleCls {
  390. width: 72rpx;
  391. height: 72rpx;
  392. background: #272636;
  393. color: #fff;
  394. border-radius: 50%;
  395. text-align: center;
  396. line-height: 72rpx;
  397. text {
  398. font-size: 52rpx;
  399. }
  400. }
  401. }
  402. }
  403. }
  404. </style>