login.vue 11 KB

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