login.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <view class="register" style="height: 100%;">
  3. <view class="content">
  4. <!-- 头部logo -->
  5. <view class="header">
  6. <image src="../../static/index/logo.jpeg" mode="widthFix"></image>
  7. </view>
  8. <!-- 主体 -->
  9. <view class="main">
  10. <view class="text-bold text-black text-xl">
  11. 欢迎使用聚联诚集团
  12. </view>
  13. <wInput v-model="phoneData" type="text" maxlength="11" placeholder="手机号"></wInput>
  14. <wInput v-model="verCode" type="number" maxlength="6" placeholder="验证码" isShowCode ref="runCode" @setCode="getVerCode()"></wInput>
  15. </view>
  16. <wButton class="wbutton" text="登 录" :rotate="isRotate" @click.native="startReg()" bgColor="linear-gradient(to right, rgb(241,197,84), rgb(241,197,84))"></wButton>
  17. <!-- <view class="flex justify-between align-center" style="margin-top: 60rpx;">
  18. <button v-if="!isphoneNum" style="margin-top: 20rpx;" :class="['buttonBorder',!istrue?'dlbutton':'dlbutton_loading']"
  19. open-type="getPhoneNumber" @getphonenumber="getphone">
  20. <view :class="istrue?'rotate_loop':''">
  21. <text v-if="istrue" class="cuIcon cuIcon-loading1"></text>
  22. <view v-if="!istrue">
  23. <slot name="text">微信授权一键登录</slot>
  24. </view>
  25. </view>
  26. </button>
  27. <button v-else style="margin-top: 20rpx;" :class="['buttonBorder',!istrue?'dlbutton':'dlbutton_loading']" open-type="getUserInfo"
  28. @getuserinfo="wxLogin">
  29. <view :class="istrue?'rotate_loop':''">
  30. <text v-if="istrue" class="cuIcon cuIcon-loading1"></text>
  31. <view v-if="!istrue">
  32. <slot name="text">微信授权一键登录</slot>
  33. </view>
  34. </view>
  35. </button>
  36. <button style="margin-top: 20rpx;color:#0B73B9 ;" class="buttonBorder dlbutton" @click="toindex()">
  37. <slot name="text">游客登录</slot>
  38. </button>
  39. </view> -->
  40. <!-- <u-popup v-model="show" mode="center" :mask-close-able="false" border-radius="16">
  41. <view style="width: 500rpx;height: 400rpx;position: relative;" class="flex flex-direction align-center justify-center">
  42. <view class="text-xl text-bold" style="position: absolute;top:30rpx">
  43. 提示
  44. </view>
  45. <view class="text-gray margin-top-sm text-lg padding-lr-sm">
  46. 需要获取用户个人信息及资料方便后续注册
  47. </view>
  48. <button open-type="getUserInfo" style="width: 100%;font-size: 32rpx;position: absolute;bottom: 0;" @getuserinfo="wxLogin">确认授权</button>
  49. </view>
  50. </u-popup> -->
  51. <!-- 底部信息 -->
  52. <view class="footer">
  53. <view class="flex align-center">
  54. <text style="color: #999999;">温馨提示:未注册聚联诚集团的手机号,登录时将自动注册</text>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- <u-no-network></u-no-network> -->
  59. </view>
  60. </template>
  61. <script>
  62. var _this;
  63. import wInput from '../../components/watch-input.vue' //input
  64. import wButton from '../../components/watch-button.vue' //button
  65. var user = require('../../common/user.js');
  66. import {
  67. mapState,
  68. mapMutations,
  69. mapGetters,
  70. mapActions
  71. } from 'vuex';
  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. // this.getCode()
  117. },
  118. onLoad() {
  119. // this.isphone()
  120. },
  121. methods: {
  122. isShowAgree() {
  123. //是否选择协议
  124. _this.showAgree = !_this.showAgree;
  125. },
  126. getVerCode: async function() {
  127. //获取验证码
  128. if (_this.phoneData.length != 11) {
  129. uni.showToast({
  130. icon: 'none',
  131. position: 'bottom',
  132. title: '手机号不正确'
  133. });
  134. return false;
  135. }
  136. let res = await this.$request.post("/api/User/sendCode", {
  137. phone: this.phoneData
  138. })
  139. console.log(res)
  140. if (res.code == 200) {
  141. this.$refs.runCode.$emit('runCode'); //触发倒计时(一般用于请求成功验证码后调用)
  142. }
  143. // _this.$refs.runCode.$emit('runCode', 0); //假装模拟下需要 终止倒计时
  144. },
  145. startReg: async function() {
  146. //注册
  147. if (this.isRotate) {
  148. //判断是否加载中,避免重复点击请求
  149. return false;
  150. }
  151. if (this.phoneData.length != 11) {
  152. uni.showToast({
  153. icon: 'none',
  154. position: 'bottom',
  155. title: '手机号不正确'
  156. });
  157. return false;
  158. }
  159. if (this.verCode.length != 6) {
  160. uni.showToast({
  161. icon: 'none',
  162. position: 'bottom',
  163. title: '验证码不正确'
  164. });
  165. return false;
  166. }
  167. _this.isRotate = true
  168. let res = await this.$request.post("/api/User/login", {
  169. phone: this.phoneData,
  170. code: this.verCode,
  171. up_id: parseInt(uni.getStorageSync('up_id'))
  172. })
  173. console.log(res)
  174. if (res.code == 200) {
  175. store.commit('setJwt', res.data.token);
  176. store.commit('setUser', res.data);
  177. store.commit('login');
  178. uni.setStorageSync('phone', this.phoneData)
  179. _this.isRotate = false
  180. uni.showToast({
  181. title: "登录成功",
  182. icon: "none"
  183. }, 1000)
  184. if(!res.data.realname){
  185. // 姓名必填 完善个人信息
  186. setTimeout(function() {
  187. uni.redirectTo({
  188. url: "/pages/mine/info"
  189. })
  190. }, 2000);
  191. } else {
  192. setTimeout(() => {
  193. uni.navigateBack({
  194. delta: 1
  195. })
  196. // uni.switchTab({
  197. // url:"../index/index"
  198. // })
  199. }, 1000)
  200. }
  201. } else {
  202. uni.showToast({
  203. icon: 'none',
  204. position: 'bottom',
  205. title: res.message
  206. });
  207. _this.isRotate = false
  208. }
  209. },
  210. isphone: async function() {
  211. },
  212. getphone: async function(e) {
  213. if (this.imgitem.istrue) {
  214. _this.istrue = true
  215. } else {
  216. uni.showToast({
  217. title: "请先同意协议",
  218. icon: "none"
  219. })
  220. }
  221. },
  222. wxLogin: async function(e) {
  223. if (e.detail.errMsg == "getUserInfo:fail auth deny") {
  224. uni.showToast({
  225. title: '微信登录失败',
  226. icon: "none"
  227. });
  228. return;
  229. }
  230. if (this.imgitem.istrue) {
  231. } else {
  232. uni.showToast({
  233. title: "请先同意协议",
  234. icon: "none"
  235. })
  236. }
  237. },
  238. toindex() {
  239. uni.switchTab({
  240. url: "../index/index"
  241. })
  242. },
  243. // isqueren() {
  244. // this.num++
  245. // if (this.num % 2 == 0) {
  246. // this.imgitem.name = "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyixuan.png"
  247. // this.imgitem.istrue = true
  248. // } else {
  249. // this.imgitem.name = "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyi.png"
  250. // this.imgitem.istrue = false
  251. // }
  252. // }
  253. }
  254. }
  255. </script>
  256. <style>
  257. @import url("../../components/colorui/icon.css");
  258. @import url("./css/main.css");
  259. page {
  260. background-color: #fff;
  261. height: 100%;
  262. }
  263. .dlbutton {
  264. display: flex;
  265. justify-content: center;
  266. align-items: center;
  267. color: #84BB43;
  268. font-size: 30rpx;
  269. white-space: nowrap;
  270. overflow: hidden;
  271. width: 294rpx;
  272. height: 88rpx;
  273. background: linear-gradient(to right, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 255.6));
  274. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.4);
  275. border-radius: 2.5rem;
  276. margin-top: 0rpx;
  277. }
  278. .dlbutton_loading {
  279. display: flex;
  280. justify-content: center;
  281. align-items: center;
  282. color: #84BB43;
  283. font-size: 30rpx;
  284. width: 100rpx;
  285. height: 100rpx;
  286. background: linear-gradient(to right, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 255.6));
  287. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.4);
  288. border-radius: 2.5rem;
  289. margin-top: 0rpx;
  290. }
  291. .buttonBorder {
  292. border: none;
  293. border-radius: 2.5rem;
  294. -webkit-box-shadow: 0 0 60rpx 0 rgba(0, 0, 0, .2);
  295. box-shadow: 0 0 60rpx 0 rgba(0, 0, 0, .2);
  296. -webkit-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  297. -moz-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  298. -ms-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  299. -o-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  300. transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  301. }
  302. /* 旋转动画 */
  303. .rotate_loop {
  304. -webkit-transition-property: -webkit-transform;
  305. -webkit-transition-duration: 1s;
  306. -moz-transition-property: -moz-transform;
  307. -moz-transition-duration: 1s;
  308. -webkit-animation: rotate 1s linear infinite;
  309. -moz-animation: rotate 1s linear infinite;
  310. -o-animation: rotate 1s linear infinite;
  311. animation: rotate 1s linear infinite;
  312. }
  313. @-webkit-keyframes rotate {
  314. from {
  315. -webkit-transform: rotate(0deg)
  316. }
  317. to {
  318. -webkit-transform: rotate(360deg)
  319. }
  320. }
  321. @-moz-keyframes rotate {
  322. from {
  323. -moz-transform: rotate(0deg)
  324. }
  325. to {
  326. -moz-transform: rotate(359deg)
  327. }
  328. }
  329. @-o-keyframes rotate {
  330. from {
  331. -o-transform: rotate(0deg)
  332. }
  333. to {
  334. -o-transform: rotate(359deg)
  335. }
  336. }
  337. @keyframes rotate {
  338. from {
  339. transform: rotate(0deg)
  340. }
  341. to {
  342. transform: rotate(359deg)
  343. }
  344. }
  345. button::after {
  346. border: none;
  347. }
  348. </style>