login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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: function() {
  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 nameLength = this.userName.split("")
  172. // if (nameLength != 13 && this.userName.indexOf("MJ") == -1) {
  173. // this.$tip.toast("该账户不是客户账号");
  174. // return
  175. // }
  176. let loginParams = {
  177. username: this.userName,
  178. password: this.password,
  179. captcha: this.captcha,
  180. requestId: this.requestId
  181. }
  182. this.loading = true;
  183. this.mLogin(loginParams).then((res) => {
  184. this.loading = false;
  185. if (res.data.state == 200) {
  186. this.$tip.success('登录成功!', 'none')
  187. this.$Router.replaceAll({
  188. name: 'index'
  189. })
  190. //账号保存到缓存中
  191. let userName = {
  192. username: this.userName
  193. }
  194. uni.setStorageSync('login-message', userName)
  195. } else {
  196. if (res.data.state == 500) {
  197. this.$tip.alert(res.data.message);
  198. } else {
  199. this.$tip.alert(res.data.cause);
  200. }
  201. }
  202. }).catch((err) => {
  203. let msg = err.data.cause || "请求出现错误,请稍后再试"
  204. this.loading = false;
  205. this.$tip.alert(msg);
  206. }).finally(() => {
  207. this.loading = false;
  208. })
  209. },
  210. zhuce() {
  211. this.$Router.push({
  212. name: "zhuce"
  213. })
  214. },
  215. refrsh() {
  216. this.Captcha();
  217. },
  218. Captcha() {
  219. this.$http.get("ibps/oauth2/v3/user/captcha?requestId=" + this.requestId + "&_t=0xxsb87").then(
  220. res => {
  221. this.iscaptcha = true
  222. this.requestId = res.data.variables.requestId;
  223. if (res.data.state == 200) {
  224. this.image = res.data.data;
  225. this.iscaptcha = true
  226. } else if (res.data.state == 501) {
  227. this.iscaptcha = false
  228. }
  229. })
  230. },
  231. //是否开启验证码 ibps/oauth2/v3/user/captcha/open 是否开始注册
  232. isCaptcha() {
  233. this.$http.get(`ibps/oauth2/v3/user/open?_t=${Ids([32, 36, 1]).next()}`).then(res => {
  234. if (res.data.state == 200) {
  235. this.requestId = res.data.variables.requestId;
  236. this.iscaptcha = res.data.data;
  237. if (this.iscaptcha) {
  238. this.Captcha();
  239. }
  240. }
  241. })
  242. },
  243. saveClientId() {
  244. var info = plus.push.getClientInfo();
  245. var cid = info.clientid;
  246. this.$http.get("/sys/user/saveClientId", {
  247. params: {
  248. clientId: cid
  249. }
  250. }).then(res => {
  251. this.$tip.success('登录成功!')
  252. this.$Router.replaceAll({
  253. name: 'index'
  254. })
  255. })
  256. },
  257. changePassword() {
  258. this.showPassword = !this.showPassword;
  259. },
  260. onSMSSend() {
  261. let smsParams = {};
  262. smsParams.phone = this.phoneNo;
  263. smsParams.smsmode = "0";
  264. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  265. if (!smsParams.phone || smsParams.phone.length == 0) {
  266. this.$tip.toast('请输入手机号');
  267. return false
  268. }
  269. if (!checkPhone.test(smsParams.phone)) {
  270. this.$tip.toast('请输入正确的手机号');
  271. return false
  272. }
  273. this.$http.post("/ibps/business/v3/mobile/sys/verification", smsParams).then(res => {
  274. if (res.data.state == 200) {
  275. this.smsCountDown = 60;
  276. this.startSMSTimer();
  277. } else {
  278. this.smsCountDown = 0;
  279. this.$tip.toast(res.data.message);
  280. }
  281. });
  282. },
  283. startSMSTimer() {
  284. this.smsCountInterval = setInterval(() => {
  285. this.smsCountDown--;
  286. if (this.smsCountDown <= 0) {
  287. clearInterval(this.smsCountInterval);
  288. }
  289. }, 1000);
  290. },
  291. sig(sql) {
  292. let rul = (sql.length + 9) * 12 * 3 + 168
  293. let salt = "JinYuanXinTong"
  294. return md5(rul + '' + salt)
  295. },
  296. onSMSLogin() {
  297. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  298. if (!this.phoneNo || this.phoneNo.length == 0) {
  299. this.$tip.toast('请填写手机号');
  300. return;
  301. }
  302. if (!checkPhone.test(this.phoneNo)) {
  303. this.$tip.toast('请输入正确的手机号');
  304. return false
  305. }
  306. if (!this.smsCode || this.smsCode.length == 0) {
  307. this.$tip.toast('请填短信验证码');
  308. return;
  309. }
  310. let loginParams = {
  311. mobile: this.phoneNo,
  312. captcha: this.smsCode
  313. };
  314. this.PhoneLogin(loginParams).then((res) => {
  315. if (res.data.state == 200) {
  316. this.$tip.success('登录成功!')
  317. this.$Router.replaceAll({
  318. name: 'index'
  319. })
  320. } else if (res.data.state == 500) {
  321. this.$tip.error(res.data.message);
  322. } else {
  323. this.$tip.error(res.data.message);
  324. }
  325. }).catch((err) => {
  326. let msg = ((err.response || {}).data || {}).message || err.data.message ||
  327. "请求出现错误,请稍后再试"
  328. this.$tip.error(msg);
  329. });
  330. },
  331. loginSuccess() {
  332. // 登陆成功,重定向到主页
  333. this.$Router.replace({
  334. name: 'index'
  335. })
  336. },
  337. requestFailed(err) {
  338. this.$message.warning("登录失败")
  339. },
  340. },
  341. beforeDestroy() {
  342. if (this.smsCountInterval) {
  343. clearInterval(this.smsCountInterval);
  344. }
  345. },
  346. }
  347. </script>
  348. <style>
  349. .login-paddingtop {
  350. padding-top: 100upx;
  351. }
  352. .zai-box {
  353. padding: 0 20upx;
  354. padding-top: 100upx;
  355. position: relative;
  356. }
  357. .zai-logo {
  358. width: 60rpx;
  359. height: 60rpx;
  360. margin-bottom: 30rpx;
  361. }
  362. .zai-title {
  363. font-size: 58rpx;
  364. color: #000000;
  365. /* text-align: center; */
  366. }
  367. .input-placeholder,
  368. .zai-input {
  369. color: #94afce;
  370. }
  371. .zai-label {
  372. padding: 60upx 0;
  373. text-align: center;
  374. font-size: 30upx;
  375. color: #a7b6d0;
  376. }
  377. .zai-btn {
  378. background: #ff65a3;
  379. color: #fff;
  380. border: 0;
  381. border-radius: 100upx;
  382. font-size: 36upx;
  383. }
  384. .zai-btn:after {
  385. border: 0;
  386. }
  387. /*按钮点击效果*/
  388. .zai-btn.button-hover {
  389. transform: translate(1upx, 1upx);
  390. }
  391. .yanzhenma {
  392. display: flex;
  393. justify-content: space-between;
  394. }
  395. .code-second {
  396. width: 100rpx;
  397. }
  398. .image-code {
  399. width: 283rpx;
  400. height: 80rpx;
  401. margin-right: 10rpx;
  402. }
  403. .logonTitle {
  404. color: #01a39e;
  405. }
  406. /deep/ .u-btn--primary {
  407. background-color: #3396d1;
  408. }
  409. </style>