index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <view class="container-mine">
  3. <navbar ref="navbar" :config="config"></navbar>
  4. <view class="top">
  5. <view class="title">手机号登录</view>
  6. <view class="tig">首次登录将为您注册</view>
  7. </view>
  8. <view class="body">
  9. <view class="inpBox">
  10. <image src="/static/czd/phone.png" mode=""></image>
  11. <input class="uni-input" v-model="mobile" type="number" maxlength="11" placeholder="输入手机号码" />
  12. </view>
  13. <view class="btnBox">
  14. <u-button type="primary" hover-class="hoverClass" @click="login">立即登录</u-button>
  15. </view>
  16. </view>
  17. <view class="more-login-way" v-if="false">
  18. <u-divider>更多登录方式</u-divider>
  19. <view class="way-btn">
  20. <view class="login-way">
  21. <view class="icon-box"><u-icon name="grid" size="60" color="#4095E5"></u-icon></view>
  22. <view class="text">宜格服务</view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="agreementCls">
  27. <u-checkbox-group size="26rpx">
  28. <u-checkbox shape="circle" active-color="#56CBD9" v-model="checked" :name="1">
  29. 我已阅读同意“宜格服务”
  30. </u-checkbox>
  31. </u-checkbox-group>
  32. <text @click="goAgreement('user_protocol')">《服务协议》</text>和<text
  33. @click="goAgreement('privacy_protocol')">《隐私政策》</text>
  34. </view>
  35. <view class="loginBox">
  36. <u-divider half-width="50">更多登录方式</u-divider>
  37. <view class="loginBox_b">
  38. <view @click="wxLogin(0)" v-if="isInstallWx||platform!='ios'">
  39. <image src="/static/czd/wx_icon.png" mode=""></image>
  40. <!-- <view>微信</view> -->
  41. </view>
  42. <view @click="alipayLogin(1)" v-if="isInstallZfb||platform!='ios'">
  43. <image src="/static/czd/zfb.png" mode=""></image>
  44. <!-- <view>支付宝</view> -->
  45. </view>
  46. <view @click="ygLogin()" v-if="isInstallWx||platform!='ios'">
  47. <image src="/static/czd/yg.png" mode=""></image>
  48. <!-- <view>宜格服务</view> -->
  49. </view>
  50. <view v-if="osVersion >= 13 && platform=='ios'" @click="appleLogin()">
  51. <image src="/static/czd/iphone_icon.png" mode=""></image>
  52. <!-- <view>苹果</view> -->
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. let app = getApp()
  60. export default {
  61. data() {
  62. return {
  63. config: {
  64. back: true, //false是tolbar页面 是则不写
  65. title: '',
  66. color: '#fff',
  67. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  68. backgroundColor: [1, '#F9F9F9'],
  69. },
  70. statusBarHeight: app.globalData.statusBarHeight,
  71. mobile: '',
  72. checked: false,
  73. osVersion: "",
  74. platform: "",
  75. isInstallWx:true,//是否安装微信
  76. isInstallZfb:true,//是否安装支付宝
  77. }
  78. },
  79. onLoad() {
  80. uni.removeStorageSync('shop')
  81. // 先判断 系统版本
  82. uni.getSystemInfo({
  83. success: (res) => {
  84. this.osVersion = res.osVersion.split('.')[0]
  85. this.platform = res.platform;
  86. }
  87. })
  88. this.isInstallWx=plus.runtime.isApplicationExist({pname:'com.tencent.mm',action:'weixin://'});
  89. this.isInstallZfb=plus.runtime.isApplicationExist({pname:'com.eg.android.AlipayGphone',action:'alipay://'});
  90. },
  91. methods: {
  92. login() {
  93. if (!this.mobile) {
  94. return this.$mUtil.toast("请输入手机号")
  95. } else if (!this.$u.test.mobile(this.mobile)) {
  96. return this.$mUtil.toast("请输入正确手机号")
  97. } else if (!this.checked) {
  98. return this.$mUtil.toast("请阅读并同意相关协议")
  99. }
  100. uni.navigateTo({
  101. url: '/pages/login/code?mobile=' + this.mobile
  102. })
  103. },
  104. goAgreement(val) {
  105. uni.navigateTo({
  106. url: "/pages/user/agreement?type=" + val
  107. })
  108. },
  109. // 微信登录
  110. wxLogin(thirdType) {
  111. if (!this.checked) {
  112. return this.$mUtil.toast("请阅读并同意相关协议")
  113. }
  114. uni.login({
  115. "provider": "weixin",
  116. "onlyAuthorize": true, // 微信登录仅请求授权认证
  117. success: (event) => {
  118. const {
  119. code
  120. } = event
  121. // console.log(event)
  122. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  123. let param = {
  124. code: code,
  125. thirdType: thirdType
  126. }
  127. this.loginRe(param)
  128. },
  129. fail: (err) => {
  130. console.log(err)
  131. // 登录授权失败
  132. // err.code是错误码
  133. this.$u.toast('当前环境不支持微信操作!');
  134. }
  135. })
  136. },
  137. loginRe(param) {
  138. this.$yghttp.post('/user/login/third', param).then(res => {
  139. console.log(res)
  140. if (res.data.isReg) {
  141. uni.showToast({
  142. title: '登录成功!',
  143. icon: 'success',
  144. duration: 1500
  145. })
  146. uni.setStorageSync('apiToken', res.data.token);
  147. this.getUsrShopInfo()
  148. uni.switchTab({
  149. url: '/pages/home'
  150. })
  151. } else {
  152. uni.navigateTo({
  153. url: "/pages/login/bindPhone?identityCode=" + res.data.identityCode +
  154. "&thirdType=" + param.thirdType
  155. })
  156. }
  157. })
  158. },
  159. // 支付宝登录
  160. alipayLogin(thirdType) {
  161. if (!this.checked) {
  162. return this.$mUtil.toast("请阅读并同意相关协议")
  163. }
  164. const AlipayAuth = uni.requireNativePlugin("DHQ-AlipayAuth");
  165. AlipayAuth.login({
  166. appId: '2021004128667996', //你在支付宝平台申请的App ID
  167. scheme: 'ygfwUrlSchemes', // 需要传到支付宝SDK的scheme,注意需要在manifest.json-->App其他常用配置-->UrlSchemes中配置Android和iOS的
  168. scope: 'auth_user', //默认为auth_user
  169. init: 'init' //默认传入init
  170. },
  171. (res) => {
  172. console.log('原生授权返回res', res)
  173. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  174. let code = res.auth_code;
  175. if(code){
  176. let param = {
  177. code: code,
  178. thirdType: thirdType
  179. }
  180. this.loginRe(param)
  181. }
  182. })
  183. },
  184. // 宜格服务登录
  185. ygLogin() {
  186. if (!this.checked) {
  187. return this.$mUtil.toast("请阅读并同意相关协议")
  188. }
  189. this.$openWXminiprogram(null, 1).then(result => {
  190. this.$yghttp.post('/user/login/yige-login', {
  191. yigeResult: result.data
  192. }).then(res => {
  193. if (res && res.code == 200) {
  194. uni.showToast({
  195. title: '登录成功!',
  196. icon: 'success',
  197. duration: 1500
  198. })
  199. uni.setStorageSync('apiToken', res.data.token);
  200. this.getUsrShopInfo()
  201. uni.switchTab({
  202. url: '/pages/home'
  203. })
  204. }
  205. })
  206. })
  207. // return false
  208. // plus.share.getServices(
  209. // res => {
  210. // let sweixin = '';
  211. // for (var i = 0; i < res.length; i++) {
  212. // let t = res[i];
  213. // if (t.id == 'weixin') {
  214. // sweixin = t;
  215. // }
  216. // }
  217. // if (sweixin) {
  218. // sweixin.launchMiniProgram({
  219. // id:"gh_9b86ebba08b0", // 要跳转小程序的原始ID
  220. // type: 2, // 微信小程序版本类型可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
  221. // path: `/pages/authLogin/authLogin?appName=宜格服务`
  222. // },
  223. // // 目标小程序点击返回App后执行的回调,在此接收微信小程序传递的参数
  224. // res2 => {
  225. // console.log(typeof res2, res2)
  226. // // res2是微信小程序传递回来的参数 类型为string 需转化为js对象使用
  227. // let result = JSON.parse(res2)
  228. // // uni.navigateTo({
  229. // // url: "/pages/login/bindPhone?yigeResult="+result.data
  230. // // })
  231. // this.$yghttp.post('/user/login/yige-login',{yigeResult:result.data}).then(res=>{
  232. // if (res && res.code == 200) {
  233. // uni.showToast({
  234. // title: '登录成功!',
  235. // icon: 'success',
  236. // duration: 1500
  237. // })
  238. // uni.setStorageSync('apiToken', res.data.token);
  239. // uni.switchTab({
  240. // url: '/pages/home'
  241. // })
  242. // }
  243. // })
  244. // // 拿到参数后执行你需要的逻辑
  245. // },
  246. // err2 => {
  247. // console.log(err2)
  248. // }
  249. // );
  250. // } else {
  251. // // 没有获取到微信分享服务
  252. // uni.showToast({
  253. // icon: 'none',
  254. // title: '当前环境不支持微信操作!'
  255. // })
  256. // }
  257. // },
  258. // err => {
  259. // // 获取分享服务列表失败
  260. // console.log(err)
  261. // }
  262. // )
  263. },
  264. // 苹果登录
  265. appleLogin() {
  266. if (!this.checked) {
  267. return this.$mUtil.toast("请阅读并同意相关协议")
  268. }
  269. // 判断是 iOS13版本
  270. uni.login({
  271. provider: 'apple',
  272. success: (loginRes) => {
  273. uni.getUserInfo({
  274. provider: 'apple',
  275. success: (userInfoRes) => {
  276. let param = {
  277. code: userInfoRes.userInfo.identityToken,
  278. thirdType: 3
  279. }
  280. this.loginRe(param)
  281. },
  282. fail: (err) => {
  283. console.log(err)
  284. }
  285. })
  286. },
  287. fail: (err) => {
  288. console.log(err)
  289. }
  290. })
  291. },
  292. // 获取商城用户店铺信息 商城接口
  293. getUsrShopInfo() {
  294. this.$http.get('/yxt/shop/loadSubShopByUserId').then(res => {
  295. if (res && res.code == 200) {
  296. uni.setStorageSync("shop", res.shop);
  297. }
  298. })
  299. },
  300. onBackPress() {
  301. uni.switchTab({
  302. url: "/pages/home"
  303. })
  304. // uni.navigateBack({
  305. // delta: 2
  306. // })
  307. return true
  308. },
  309. }
  310. }
  311. </script>
  312. <style>
  313. page {
  314. background-color: #F9F9F9;
  315. }
  316. </style>
  317. <style lang="scss" scoped>
  318. /deep/ .hx-navbar__icon {
  319. color: #303133 !important;
  320. }
  321. /deep/.u-divider {
  322. background-color: #F9F9F9 !important;
  323. }
  324. .lgoin-nav {
  325. width: 100%;
  326. background-color: #fff;
  327. position: fixed;
  328. left: 0;
  329. right: 0;
  330. top: 0;
  331. z-index: 0;
  332. }
  333. .top {
  334. text-align: center;
  335. padding: 50rpx 0 100rpx;
  336. font-size: 28rpx;
  337. .title {
  338. font-size: 60rpx;
  339. margin-bottom: 10rpx;
  340. font-weight: 700;
  341. }
  342. .tig {
  343. font-size: 30rpx;
  344. }
  345. }
  346. .body {
  347. margin: auto;
  348. width: 615rpx;
  349. margin-bottom: 30rpx;
  350. .inpBox {
  351. background: #fff;
  352. border-radius: 20rpx;
  353. padding: 20rpx 30rpx;
  354. display: flex;
  355. }
  356. image {
  357. width: 36rpx;
  358. height: 44rpx;
  359. margin-right: 30rpx;
  360. }
  361. .uni-input {
  362. height: 40rpx;
  363. .uni-input-placeholder {
  364. color: #BEBEBE;
  365. }
  366. }
  367. .login-btn {
  368. background-color: #4095E5;
  369. color: #fff;
  370. margin-top: 100rpx;
  371. }
  372. }
  373. .more-login-way {
  374. .way-btn {
  375. display: flex;
  376. align-items: center;
  377. justify-content: center;
  378. margin-top: 30rpx;
  379. .login-way {
  380. display: flex;
  381. flex-direction: column;
  382. align-items: center;
  383. .icon-box {
  384. display: flex;
  385. justify-content: center;
  386. align-items: center;
  387. width: 80rpx;
  388. height: 80rpx;
  389. margin-bottom: 10rpx;
  390. border: 1rpx solid #EFEFEF;
  391. border-radius: 50%;
  392. }
  393. .text {
  394. color: #101010;
  395. }
  396. }
  397. }
  398. }
  399. .agreementCls {
  400. margin: auto;
  401. width: 615rpx;
  402. font-size: 26rpx;
  403. display: flex;
  404. align-items: center;
  405. flex-wrap: wrap;
  406. /deep/ .u-checkbox__label {
  407. margin-right: 0rpx;
  408. font-size: 26rpx;
  409. }
  410. text {
  411. color: #56CBD9;
  412. }
  413. }
  414. .loginBox {
  415. width: 100%;
  416. position: absolute;
  417. bottom: 100rpx;
  418. .loginBox_b {
  419. width: 615rpx;
  420. display: flex;
  421. justify-content: space-around;
  422. margin: auto;
  423. margin-top: 60rpx;
  424. >view {
  425. text-align: center;
  426. image {
  427. width: 82rpx;
  428. height: 82rpx;
  429. border-radius: 50%;
  430. }
  431. >view {
  432. font-size: 26rpx;
  433. color: #333333;
  434. }
  435. }
  436. }
  437. }
  438. .btnBox {
  439. width: 100%;
  440. margin-top: 60rpx;
  441. }
  442. .u-btn {
  443. width: 615rpx;
  444. border-radius: 10rpx;
  445. background: rgb(64, 149, 229);
  446. font-size: 30rpx;
  447. font-weight: 700;
  448. margin: auto;
  449. font-family: Microsoft YaHei, Microsoft YaHei-Bold;
  450. background: linear-gradient(6deg, #56d9ee 0%, #3ebcd0 100%) #3c66d9;
  451. }
  452. .hoverClass {
  453. background: linear-gradient(6deg, #56d9ee 0%, #3ebcd0 100%) #3c66d9;
  454. }
  455. </style>