login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <template>
  2. <view class="register">
  3. <view class="content">
  4. <!-- 头部logo -->
  5. <view class="header">
  6. <image src="https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/loginlogo.png"></image>
  7. </view>
  8. <!-- 主体 -->
  9. <view class="main">
  10. <wInput v-model="phoneData" type="text" maxlength="11" placeholder="手机号"></wInput>
  11. <wInput v-model="verCode" type="number" maxlength="6" placeholder="验证码" isShowCode ref="runCode" @setCode="getVerCode()"></wInput>
  12. </view>
  13. <wButton class="wbutton" text="登 录" :rotate="isRotate" @click.native="startReg()" bgColor="linear-gradient(to right, rgba(11,115,185,0.7), rgba(11,115,185,0.6))"></wButton>
  14. <view class="flex justify-between align-center" style="margin-top: 60rpx;">
  15. <button v-if="!isphoneNum" style="margin-top: 20rpx;" :class="['buttonBorder',!istrue?'dlbutton':'dlbutton_loading']"
  16. open-type="getPhoneNumber" @getphonenumber="getphone">
  17. <view :class="istrue?'rotate_loop':''">
  18. <text v-if="istrue" class="cuIcon cuIcon-loading1"></text>
  19. <view v-if="!istrue">
  20. <slot name="text">微信授权一键登录</slot>
  21. </view>
  22. </view>
  23. </button>
  24. <button v-else style="margin-top: 20rpx;" :class="['buttonBorder',!istrue?'dlbutton':'dlbutton_loading']" open-type="getUserInfo"
  25. @getuserinfo="wxLogin">
  26. <view :class="istrue?'rotate_loop':''">
  27. <text v-if="istrue" class="cuIcon cuIcon-loading1"></text>
  28. <view v-if="!istrue">
  29. <slot name="text">微信授权一键登录</slot>
  30. </view>
  31. </view>
  32. </button>
  33. <button style="margin-top: 20rpx;color:#0B73B9 ;" class="buttonBorder dlbutton" @click="toindex()">
  34. <slot name="text">游客登录</slot>
  35. </button>
  36. </view>
  37. <u-popup v-model="show" mode="center" :mask-close-able="false" border-radius="16">
  38. <view style="width: 500rpx;height: 400rpx;position: relative;" class="flex flex-direction align-center justify-center">
  39. <view class="text-xl text-bold" style="position: absolute;top:30rpx">
  40. 提示
  41. </view>
  42. <view class="text-gray margin-top-sm text-lg padding-lr-sm">
  43. 需要获取用户个人信息及资料方便后续注册
  44. </view>
  45. <button open-type="getUserInfo" style="width: 100%;font-size: 32rpx;position: absolute;bottom: 0;" @getuserinfo="wxLogin">确认授权</button>
  46. </view>
  47. </u-popup>
  48. <!-- 底部信息 -->
  49. <view class="footer">
  50. <view class="flex align-center" @click="isqueren">
  51. <image :src="imgitem.name" mode="" style="width: 30rpx;height: 30rpx;"></image>
  52. <text style="color: #0B73B9;">《超级宝妈宝》</text>
  53. <text style="color: #999999;">服务协议</text>
  54. </view>
  55. </view>
  56. </view>
  57. <u-no-network></u-no-network>
  58. </view>
  59. </template>
  60. <script>
  61. var _this;
  62. import wInput from '../../components/watch-input.vue' //input
  63. import wButton from '../../components/watch-button.vue' //button
  64. var user = require('../../common/user.js');
  65. import {
  66. mapState,
  67. mapMutations,
  68. mapGetters,
  69. mapActions
  70. } from 'vuex';
  71. import IMService from "../../common/goeasyimutil.js";
  72. import store from '@/store'
  73. export default {
  74. computed: {
  75. ...mapGetters({
  76. hasLogin: 'verifyJwt'
  77. }),
  78. ...mapState(['user'])
  79. },
  80. data() {
  81. return {
  82. //logo图片 base64
  83. phoneData: '', // 用户/电话
  84. verCode: "", //验证码
  85. showAgree: true, //协议是否选择
  86. isRotate: false, //是否加载旋转
  87. istrue: false,
  88. num: 1,
  89. imgitem: {
  90. istrue: false,
  91. name: "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyi.png"
  92. },
  93. show: false,
  94. isphoneNum: false
  95. }
  96. },
  97. // onShow() {
  98. // uni.checkSession({
  99. // success() {
  100. // console.log("已登录")
  101. // return;
  102. // },
  103. // fail() {
  104. // uni.navigateTo({
  105. // url: "../doctor_related/doctor_info"
  106. // })
  107. // }
  108. // })
  109. // },
  110. components: {
  111. wInput,
  112. wButton,
  113. },
  114. mounted() {
  115. _this = this;
  116. },
  117. onLoad() {
  118. this.isphone()
  119. },
  120. methods: {
  121. isShowAgree() {
  122. //是否选择协议
  123. _this.showAgree = !_this.showAgree;
  124. },
  125. getVerCode: async function() {
  126. //获取验证码
  127. if (_this.phoneData.length != 11) {
  128. uni.showToast({
  129. icon: 'none',
  130. position: 'bottom',
  131. title: '手机号不正确'
  132. });
  133. return false;
  134. }
  135. let res = await this.$request.post("/api/v1/common/sendVerifyCode", {
  136. phone: this.phoneData,
  137. type: 1
  138. })
  139. console.log(res)
  140. if (res.status == 0) {
  141. this.$refs.runCode.$emit('runCode'); //触发倒计时(一般用于请求成功验证码后调用)
  142. }
  143. // _this.$refs.runCode.$emit('runCode', 0); //假装模拟下需要 终止倒计时
  144. },
  145. startReg: function() {
  146. //注册
  147. if (this.isRotate) {
  148. //判断是否加载中,避免重复点击请求
  149. return false;
  150. }
  151. if (!this.imgitem.istrue) {
  152. uni.showToast({
  153. icon: 'none',
  154. position: 'bottom',
  155. title: '请先同意协议'
  156. });
  157. return false;
  158. }
  159. if (this.phoneData.length != 11) {
  160. uni.showToast({
  161. icon: 'none',
  162. position: 'bottom',
  163. title: '手机号不正确'
  164. });
  165. return false;
  166. }
  167. if (this.verCode.length != 6) {
  168. uni.showToast({
  169. icon: 'none',
  170. position: 'bottom',
  171. title: '验证码不正确'
  172. });
  173. return false;
  174. }
  175. uni.login({
  176. success: (res) => {
  177. _this.isRotate = true
  178. this.$request.post("/api/v1/common/wxLogin", {
  179. wechat_code: res.code,
  180. phone: this.phoneData,
  181. verify_code: this.verCode
  182. }).then(res => {
  183. if (res.status == 0) {
  184. if (res.data.token) {
  185. store.commit('setJwt', res.data.token);
  186. store.commit('setUser', res.data);
  187. store.commit('login');
  188. uni.showToast({
  189. title: "登录成功",
  190. icon: "none"
  191. }, 1500)
  192. setTimeout(() => {
  193. uni.navigateBack({
  194. delta: 1
  195. })
  196. }, 1500)
  197. }
  198. }
  199. }).catch(err => {
  200. })
  201. }
  202. })
  203. },
  204. isphone: async function() {
  205. uni.login({
  206. success: (re) => {
  207. this.$request.post("/api/v1/common/getUserByCode", {
  208. wechat_code: re.code
  209. }).then(data => {
  210. console.log(data)
  211. if (data.data != null && data.data.phone != "") {
  212. uni.setStorageSync('phone', data.data.phone)
  213. this.isphoneNum = true
  214. }
  215. }).catch(err => {
  216. })
  217. }
  218. })
  219. },
  220. getphone: async function(e) {
  221. if (this.imgitem.istrue) {
  222. _this.istrue = true
  223. uni.login({
  224. success: (res) => {
  225. console.log(res)
  226. this.$request.post("/api/v1/common/getPhoneNumber", {
  227. wechat_code: res.code,
  228. iv: e.detail.iv,
  229. encryptData: e.detail.encryptedData
  230. }).then(data => {
  231. console.log(data)
  232. if (data.status == 0) {
  233. this.show = true
  234. } else {
  235. _this.istrue = false
  236. uni.showToast({
  237. title: "授权失败",
  238. icon: "none"
  239. })
  240. }
  241. }).catch(err => {
  242. })
  243. }
  244. })
  245. } else {
  246. uni.showToast({
  247. title: "请先同意协议",
  248. icon: "none"
  249. })
  250. }
  251. },
  252. wxLogin: async function(e) {
  253. if (e.detail.errMsg == "getUserInfo:fail auth deny") {
  254. uni.showToast({
  255. title: '微信登录失败',
  256. icon: "none"
  257. });
  258. return;
  259. }
  260. if (this.imgitem.istrue) {
  261. user.loginByWeixin(e.detail.userInfo)
  262. .then(res => {
  263. this.show = false
  264. if (res.status == 0) {
  265. getApp().globalData.imService = new IMService();
  266. let loginResult = getApp().globalData.imService.login(res.data);
  267. if (loginResult) {
  268. //连接IM
  269. getApp().globalData.imService.connectIM();
  270. }
  271. uni.showToast({
  272. title: "登录成功",
  273. icon: "none",
  274. duration: 2000
  275. })
  276. }
  277. setTimeout(function() {
  278. _this.istrue = false
  279. uni.navigateBack({
  280. delta: 1
  281. })
  282. }, 2000)
  283. })
  284. .catch(res => {
  285. uni.showToast({
  286. title: '微信登录失败',
  287. icon: "none"
  288. });
  289. });
  290. } else {
  291. uni.showToast({
  292. title: "请先同意协议",
  293. icon: "none"
  294. })
  295. }
  296. },
  297. toindex() {
  298. uni.switchTab({
  299. url: "../index/index"
  300. })
  301. },
  302. isqueren() {
  303. this.num++
  304. if (this.num % 2 == 0) {
  305. this.imgitem.name = "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyixuan.png"
  306. this.imgitem.istrue = true
  307. } else {
  308. this.imgitem.name = "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyi.png"
  309. this.imgitem.istrue = false
  310. }
  311. }
  312. }
  313. }
  314. </script>
  315. <style>
  316. @import url("../../components/colorui/icon.css");
  317. @import url("./css/main.css");
  318. page {
  319. background-color: #fff;
  320. }
  321. .dlbutton {
  322. display: flex;
  323. justify-content: center;
  324. align-items: center;
  325. color: #84BB43;
  326. font-size: 30rpx;
  327. white-space: nowrap;
  328. overflow: hidden;
  329. width: 294rpx;
  330. height: 88rpx;
  331. background: linear-gradient(to right, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 255.6));
  332. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.4);
  333. border-radius: 2.5rem;
  334. margin-top: 0rpx;
  335. }
  336. .dlbutton_loading {
  337. display: flex;
  338. justify-content: center;
  339. align-items: center;
  340. color: #84BB43;
  341. font-size: 30rpx;
  342. width: 100rpx;
  343. height: 100rpx;
  344. background: linear-gradient(to right, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 255.6));
  345. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.4);
  346. border-radius: 2.5rem;
  347. margin-top: 0rpx;
  348. }
  349. .buttonBorder {
  350. border: none;
  351. border-radius: 2.5rem;
  352. -webkit-box-shadow: 0 0 60rpx 0 rgba(0, 0, 0, .2);
  353. box-shadow: 0 0 60rpx 0 rgba(0, 0, 0, .2);
  354. -webkit-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  355. -moz-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  356. -ms-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  357. -o-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  358. transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  359. }
  360. /* 旋转动画 */
  361. .rotate_loop {
  362. -webkit-transition-property: -webkit-transform;
  363. -webkit-transition-duration: 1s;
  364. -moz-transition-property: -moz-transform;
  365. -moz-transition-duration: 1s;
  366. -webkit-animation: rotate 1s linear infinite;
  367. -moz-animation: rotate 1s linear infinite;
  368. -o-animation: rotate 1s linear infinite;
  369. animation: rotate 1s linear infinite;
  370. }
  371. @-webkit-keyframes rotate {
  372. from {
  373. -webkit-transform: rotate(0deg)
  374. }
  375. to {
  376. -webkit-transform: rotate(360deg)
  377. }
  378. }
  379. @-moz-keyframes rotate {
  380. from {
  381. -moz-transform: rotate(0deg)
  382. }
  383. to {
  384. -moz-transform: rotate(359deg)
  385. }
  386. }
  387. @-o-keyframes rotate {
  388. from {
  389. -o-transform: rotate(0deg)
  390. }
  391. to {
  392. -o-transform: rotate(359deg)
  393. }
  394. }
  395. @keyframes rotate {
  396. from {
  397. transform: rotate(0deg)
  398. }
  399. to {
  400. transform: rotate(359deg)
  401. }
  402. }
  403. button::after {
  404. border: none;
  405. }
  406. </style>