login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <view class="zai-box">
  3. <scroll-view scroll-y class="page">
  4. <view class="flex-center-center" :style="[{animation: 'show ' + 0.4+ 's 1'}]">
  5. <image src="../login/luohuLogo.png" mode='aspectFit' class="zai-logo "
  6. style="position: relative;top: 16rpx;margin-right: 5rpx;"></image>
  7. <view class="zai-title text-shadow logonTitle" style="font-size: 45rpx">深圳市罗湖医院集团</view>
  8. </view>
  9. <view class="flex-center-center" :style="[{animation: 'show ' + 0.4+ 's 1'}]">
  10. <view class="zai-title text-shadow logonTitle">细胞质量检测服务平台</view>
  11. </view>
  12. <view class="box padding-lr-xl login-paddingtop" :style="[{animation: 'show ' + 0.6+ 's 1'}]">
  13. <block v-if="loginWay==1">
  14. <view class="cu-form-group margin-top shadow-warp" :class="[shape=='round'?'round':'']">
  15. <view class="title"><text class="cuIcon-people margin-right-xs"></text>账号:</view>
  16. <input placeholder="请输入账号" name="input" v-model="userName"></input>
  17. </view>
  18. <view class="cu-form-group margin-top shadow-warp" :class="[shape=='round'?'round':'']">
  19. <view class="title"><text class="cuIcon-lock margin-right-xs"></text>密码:</view>
  20. <input class="uni-input" placeholder="请输入密码" :password="!showPassword" v-model="password" />
  21. <view class="action text-lg">
  22. <text :class="[showPassword ? 'cuIcon-attention' : 'cuIcon-attentionforbid']"
  23. @click="changePassword"></text>
  24. </view>
  25. </view>
  26. <view class="cu-form-group margin-top shadow-warp yanzhenma" v-if="iscaptcha"
  27. :class="[shape=='round'?'round':'']" style="padding: 0;">
  28. <view class="code-second">
  29. <input class="code-yanzheng" style="width: 220rpx;padding-left: 20rpx;" placeholder="请输入验证码"
  30. v-model="captcha" />
  31. </view>
  32. <view class="image-code" @click="refrsh">
  33. <image :src="image" style="width: 100%;height: 100%;"></image>
  34. </view>
  35. </view>
  36. <view class="m-t-100">
  37. <u-button type="primary" :loading="loading" @click="onLogin" iconColor="#3396d1">
  38. {{loading ? "登录中...":" 登录 "}}
  39. </u-button>
  40. </view>
  41. </block>
  42. <block v-else>
  43. <view class="cu-form-group margin-top shadow-warp" :class="[shape=='round'?'round':'']">
  44. <view class="title"><text class="cuIcon-mobile margin-right-xs"></text>手机号:</view>
  45. <input placeholder="请输入手机号" type="number" maxlength="11" v-model="phoneNo"></input>
  46. </view>
  47. <view class="cu-form-group margin-top shadow-warp" :class="[shape=='round'?'round':'']">
  48. <view class="title"><text class="cuIcon-lock margin-right-xs"></text>验证码:</view>
  49. <input class="uni-input" placeholder="请输入验证码" v-model="smsCode" />
  50. <view class="action">
  51. <button class="cu-btn line-blue sm" :disabled="!isSendSMSEnable" @click="onSMSSend">
  52. {{ getSendBtnText }}</button>
  53. </view>
  54. </view>
  55. <view @tap="zhuce()"> <text style="color: #E04B28;float: right; margin-right: 20rpx; ">
  56. 还未注册?请注册</text> </view>
  57. <view class="padding text-center margin-top">
  58. <button class="cu-btn bg-blue lg margin-right shadow" :loading="loading"
  59. :class="[shape=='round'?'round':'']" @tap="onSMSLogin"><text
  60. space="emsp">{{loading ? "登录中...":" 登录 "}}</text>
  61. </button>
  62. <!-- <button class="cu-btn line-blue lg margin-left shadow" :loading="loading" :class="[shape=='round'?'round':'']"
  63. @tap="loginWay=1">账户登录
  64. </button> -->
  65. </view>
  66. </block>
  67. <!-- #ifdef APP-PLUS -->
  68. <view class="padding flex flex-direction text-center">
  69. 当前版本:{{version}}
  70. </view>
  71. <!-- #endif -->
  72. </view>
  73. </scroll-view>
  74. <!-- 登录加载弹窗 -->
  75. <view class="cu-load load-modal" v-if="loading">
  76. <!-- <view class="cuIcon-emojifill text-orange"></view> -->
  77. <!-- <image src="https://static.jeecg.com/upload/test/login4_1595818039175.png" mode="aspectFit" class="round"></image>
  78. -->
  79. <view class="gray-text">登录中...</view>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. import Ids from 'ids'
  85. import {
  86. ACCESS_TOKEN,
  87. USER_NAME,
  88. USER_INFO
  89. } from "@/common/util/constants"
  90. import {
  91. mapActions
  92. } from "vuex"
  93. import configService from '@/common/service/config.service.js';
  94. import md5 from "@/common/util/md5.js"
  95. export default {
  96. data() {
  97. return {
  98. iscaptcha: false,
  99. captcha: '',
  100. requestId: '',
  101. image: '',
  102. shape: '', //round 圆形
  103. loading: false,
  104. userName: '',
  105. password: '',
  106. phoneNo: '',
  107. smsCode: '',
  108. showPassword: false, //是否显示明文
  109. loginWay: 1, //1: 账密,2:验证码
  110. smsCountDown: 0,
  111. smsCountInterval: null,
  112. toggleDelay: false,
  113. version: '',
  114. //第三方登录相关信息
  115. thirdType: "",
  116. thirdLoginInfo: "",
  117. thirdLoginState: false,
  118. bindingPhoneModal: false,
  119. thirdUserUuid: '',
  120. url: {
  121. bindingThirdPhone: '/sys/thirdLogin/bindingThirdPhone'
  122. }
  123. };
  124. },
  125. onLoad: function() {
  126. //检测需要开启验证码
  127. // this.isCaptcha();
  128. this.Captcha()
  129. // #ifdef APP-PLUS
  130. var that = this
  131. plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
  132. that.version = wgtinfo.version
  133. });
  134. // #endif
  135. },
  136. created() {
  137. let loginMessage2 = uni.getStorageSync('login-message')
  138. if (loginMessage2) {
  139. this.userName = loginMessage2.username
  140. }
  141. },
  142. computed: {
  143. isSendSMSEnable() {
  144. return this.smsCountDown <= 0 && this.phoneNo.length > 4;
  145. },
  146. getSendBtnText() {
  147. if (this.smsCountDown > 0) {
  148. return this.smsCountDown + '秒后发送';
  149. } else {
  150. return '发送验证码';
  151. }
  152. },
  153. canSMSLogin() {
  154. return this.userName.length > 4 && this.smsCode.length > 4;
  155. },
  156. canPwdLogin() {
  157. return this.userName.length > 4 && this.password.length > 4;
  158. },
  159. },
  160. methods: {
  161. ...mapActions(["mLogin", "PhoneLogin", "mSign", "ThirdLogin"]),
  162. onLogin() {
  163. if (!this.userName || this.userName.length == 0) {
  164. this.$tip.toast('请填写用户名');
  165. return;
  166. }
  167. if (!this.password || this.password.length == 0) {
  168. this.$tip.toast('请填写密码');
  169. return;
  170. }
  171. let loginParams = {
  172. username: this.userName,
  173. password: this.password,
  174. captcha: this.captcha,
  175. requestId: this.requestId
  176. }
  177. this.loading = true;
  178. this.mLogin(loginParams).then((res) => {
  179. this.loading = false;
  180. if (res.data.state == 200) {
  181. this.$tip.success('登录成功!', 'none')
  182. this.$Router.replaceAll({
  183. name: 'index'
  184. })
  185. //账号保存到缓存中
  186. let userName = {
  187. username: this.userName
  188. }
  189. uni.setStorageSync('login-message', userName)
  190. } else {
  191. if (res.data.state == 500) {
  192. this.$tip.alert(res.data.message);
  193. } else {
  194. this.$tip.alert(res.data.cause);
  195. }
  196. }
  197. }).catch((err) => {
  198. this.loading = false;
  199. })
  200. },
  201. zhuce() {
  202. this.$Router.push({
  203. name: "zhuce"
  204. })
  205. },
  206. refrsh() {
  207. this.Captcha();
  208. },
  209. Captcha() {
  210. this.$http.get("ibps/oauth2/v3/user/captcha?requestId=" + this.requestId + "&_t=0xxsb87").then(
  211. res => {
  212. this.iscaptcha = true
  213. this.requestId = res.data.variables.requestId;
  214. if (res.data.state == 200) {
  215. this.image = res.data.data;
  216. this.iscaptcha = true
  217. } else if (res.data.state == 501) {
  218. this.iscaptcha = false
  219. }
  220. })
  221. },
  222. //是否开启验证码 ibps/oauth2/v3/user/captcha/open 是否开始注册
  223. isCaptcha() {
  224. this.$http.get(`ibps/oauth2/v3/user/open?_t=${Ids([32, 36, 1]).next()}`).then(res => {
  225. if (res.data.state == 200) {
  226. this.requestId = res.data.variables.requestId;
  227. this.iscaptcha = res.data.data;
  228. if (this.iscaptcha) {
  229. this.Captcha();
  230. }
  231. }
  232. })
  233. },
  234. saveClientId() {
  235. var info = plus.push.getClientInfo();
  236. var cid = info.clientid;
  237. this.$http.get("/sys/user/saveClientId", {
  238. params: {
  239. clientId: cid
  240. }
  241. }).then(res => {
  242. this.$tip.success('登录成功!')
  243. this.$Router.replaceAll({
  244. name: 'index'
  245. })
  246. })
  247. },
  248. changePassword() {
  249. this.showPassword = !this.showPassword;
  250. },
  251. onSMSSend() {
  252. let smsParams = {};
  253. smsParams.phone = this.phoneNo;
  254. smsParams.smsmode = "0";
  255. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  256. if (!smsParams.phone || smsParams.phone.length == 0) {
  257. this.$tip.toast('请输入手机号');
  258. return false
  259. }
  260. if (!checkPhone.test(smsParams.phone)) {
  261. this.$tip.toast('请输入正确的手机号');
  262. return false
  263. }
  264. this.$http.post("/ibps/business/v3/mobile/sys/verification", smsParams).then(res => {
  265. if (res.data.state == 200) {
  266. this.smsCountDown = 60;
  267. this.startSMSTimer();
  268. } else {
  269. this.smsCountDown = 0;
  270. this.$tip.toast(res.data.message);
  271. }
  272. });
  273. },
  274. startSMSTimer() {
  275. this.smsCountInterval = setInterval(() => {
  276. this.smsCountDown--;
  277. if (this.smsCountDown <= 0) {
  278. clearInterval(this.smsCountInterval);
  279. }
  280. }, 1000);
  281. },
  282. sig(sql) {
  283. let rul = (sql.length + 9) * 12 * 3 + 168
  284. let salt = "JinYuanXinTong"
  285. return md5(rul + '' + salt)
  286. },
  287. onSMSLogin() {
  288. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  289. if (!this.phoneNo || this.phoneNo.length == 0) {
  290. this.$tip.toast('请填写手机号');
  291. return;
  292. }
  293. if (!checkPhone.test(this.phoneNo)) {
  294. this.$tip.toast('请输入正确的手机号');
  295. return false
  296. }
  297. if (!this.smsCode || this.smsCode.length == 0) {
  298. this.$tip.toast('请填短信验证码');
  299. return;
  300. }
  301. let loginParams = {
  302. mobile: this.phoneNo,
  303. captcha: this.smsCode
  304. };
  305. this.PhoneLogin(loginParams).then((res) => {
  306. if (res.data.state == 200) {
  307. this.$tip.success('登录成功!')
  308. this.$Router.replaceAll({
  309. name: 'index'
  310. })
  311. } else if (res.data.state == 500) {
  312. this.$tip.error(res.data.message);
  313. } else {
  314. this.$tip.error(res.data.message);
  315. }
  316. }).catch((err) => {
  317. let msg = ((err.response || {}).data || {}).message || err.data.message ||
  318. "请求出现错误,请稍后再试"
  319. this.$tip.error(msg);
  320. });
  321. },
  322. loginSuccess() {
  323. // 登陆成功,重定向到主页
  324. this.$Router.replace({
  325. name: 'index'
  326. })
  327. },
  328. requestFailed(err) {
  329. this.$message.warning("登录失败")
  330. },
  331. },
  332. beforeDestroy() {
  333. if (this.smsCountInterval) {
  334. clearInterval(this.smsCountInterval);
  335. }
  336. },
  337. }
  338. </script>
  339. <style>
  340. .login-paddingtop {
  341. padding-top: 100upx;
  342. }
  343. .zai-box {
  344. padding: 0 20upx;
  345. padding-top: 100upx;
  346. position: relative;
  347. }
  348. .zai-logo {
  349. width: 60rpx;
  350. height: 60rpx;
  351. margin-bottom: 30rpx;
  352. }
  353. .zai-title {
  354. font-size: 58rpx;
  355. color: #000000;
  356. /* text-align: center; */
  357. }
  358. .input-placeholder,
  359. .zai-input {
  360. color: #94afce;
  361. }
  362. .zai-label {
  363. padding: 60upx 0;
  364. text-align: center;
  365. font-size: 30upx;
  366. color: #a7b6d0;
  367. }
  368. .zai-btn {
  369. background: #ff65a3;
  370. color: #fff;
  371. border: 0;
  372. border-radius: 100upx;
  373. font-size: 36upx;
  374. }
  375. .zai-btn:after {
  376. border: 0;
  377. }
  378. /*按钮点击效果*/
  379. .zai-btn.button-hover {
  380. transform: translate(1upx, 1upx);
  381. }
  382. .yanzhenma {
  383. display: flex;
  384. justify-content: space-between;
  385. }
  386. .code-second {
  387. width: 100rpx;
  388. }
  389. .image-code {
  390. width: 283rpx;
  391. height: 80rpx;
  392. margin-right: 10rpx;
  393. }
  394. .logonTitle {
  395. color: #01a39e;
  396. }
  397. /deep/ .u-btn--primary {
  398. background-color: #3396d1;
  399. }
  400. </style>