Login.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. <template>
  2. <view>
  3. <view v-show="accountIsShow">
  4. <view class="title">账号密码登录</view>
  5. <view class="usernameAndPassword">
  6. <view class="usernameContent">
  7. <input type="text" v-model="username" placeholder="账号" @input="usernameInput" />
  8. </view>
  9. <view class="passwordContent">
  10. <input type="text" v-model="password" :password="passwordShow" placeholder="请输入密码" @input="passwordInput" />
  11. <sunui-password @change="showPass" />
  12. </view>
  13. </view>
  14. <view class="type" :style="{ 'margin-top': typeMarginTop }">
  15. <a @tap="changeType('phone')">手机验证码登录</a>
  16. <a style="float: right;color:#77A8E6;" @tap="goToIndex()">游客身份登录</a>
  17. </view>
  18. <button class="cu-btn bg-red lg" @tap="login" :disabled="usernameLoginDisabled" type="" :style="{ 'height': buttonHeight}">登录</button>
  19. <button class="cu-btn bg-red lg" @tap="checkIsSoterEnrolledInDeviceFingerPrint" type="" :style="{ 'height': buttonHeight}">指纹登录</button>
  20. <view class="bottomWord" :style="{ 'font-size': bottomWordFontSize,'margin-top':bottomWordMarginTop}">
  21. 点击登录,即代表已阅读并同意<a href="#">隐私政策</a>和<a href="#">用户协议</a>
  22. </view>
  23. </view>
  24. <view v-show="phoneIsShow">
  25. <view class="title">手机验证码登录</view>
  26. <view class="usernameAndPassword">
  27. <view class="phoneContent">
  28. <span>+86</span>
  29. <input type="text" v-model="phone" placeholder="请输入手机号码" @input="phoneInput" />
  30. </view>
  31. <view class="codeContent">
  32. <input type="text" v-model="code" placeholder="请输入验证码" @input="codeInput" />
  33. <span :style="{ 'color': codeColor,'width':codeWidth }" @tap="getCode">获取验证码</span>
  34. </view>
  35. </view>
  36. <view class="type" :style="{ 'margin-top': typeMarginTop }">
  37. <a @tap="changeType('account')">账号登录</a>
  38. </view>
  39. <button class="cu-btn bg-red lg" :disabled="codeLoginDisabled" type="" :style="{ 'height': buttonHeight}">登录</button>
  40. <view class="bottomWord" :style="{ 'font-size': bottomWordFontSize,'margin-top':bottomWordMarginTop}">
  41. 点击登录,即代表已阅读并同意<a href="#">隐私政策</a>和<a href="#">用户协议</a>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data: function() {
  49. return {
  50. passwordShow: true,
  51. accountIsShow: true,
  52. phoneIsShow: false,
  53. usernameLoginDisabled: true,
  54. codeLoginDisabled: true,
  55. username: '',
  56. password: '',
  57. phone: "",
  58. code: "",
  59. codeColor: "#808080",
  60. usernameFlag: false,
  61. passwordFlag: false,
  62. phoneFlag: false,
  63. codeFlag: false,
  64. getCodeFlag: false,
  65. lastUserName: '',
  66. lastPassWord: '',
  67. windowWidth: "",
  68. windowHeight: "",
  69. typeMarginTop: "",
  70. codeWidth: "",
  71. bottomWordFontSize: "",
  72. bottomWordMarginTop: "",
  73. buttonHeight: ""
  74. };
  75. },
  76. created() {
  77. this.windowWidth = uni.getSystemInfoSync().windowWidth;
  78. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  79. //console.log(this.windowWidth);
  80. if (this.windowWidth >= 768) {
  81. this.typeMarginTop = "10%";
  82. this.codeWidth = "200px";
  83. this.bottomWordFontSize = "18px";
  84. this.bottomWordMarginTop = "500px";
  85. this.buttonHeight = "50px";
  86. } else {
  87. this.typeMarginTop = "0";
  88. this.codeWidth = "100px";
  89. this.bottomWordFontSize = "13px";
  90. this.bottomWordMarginTop = "270px";
  91. this.buttonHeight = "40px";
  92. }
  93. //this.removeUsernamePassword();
  94. this.getUsernamePassword();
  95. },
  96. computed: {
  97. backStageIp: function() {
  98. return this.$store.state.wholeSituationBackStageIp;
  99. },
  100. backStagePort: function() {
  101. return this.$store.state.wholeSituationBackStagePort;
  102. },
  103. windpowerstationNameToId: function() {
  104. return this.$store.state.windpowerstationNameToId;
  105. }
  106. },
  107. methods: {
  108. showPass(e) {
  109. this.passwordShow = e;
  110. },
  111. usernameInput(e) {
  112. if (e.detail.value != "") {
  113. this.usernameFlag = true;
  114. if (this.passwordFlag) {
  115. this.usernameLoginDisabled = false;
  116. }
  117. } else {
  118. this.usernameFlag = false;
  119. this.usernameLoginDisabled = true;
  120. }
  121. },
  122. passwordInput(e) {
  123. if (e.detail.value != "") {
  124. this.passwordFlag = true;
  125. if (this.usernameFlag) {
  126. this.usernameLoginDisabled = false;
  127. }
  128. } else {
  129. this.passwordFlag = false;
  130. this.usernameLoginDisabled = true;
  131. }
  132. },
  133. phoneInput(e) {
  134. // console.log(e.detail.value)
  135. var phoneStr = e.detail.value;
  136. if (/^1(3|4|5|6|7|8|9)\d{9}$/.test(phoneStr)) {
  137. this.codeColor = "black";
  138. this.getCodeFlag = true;
  139. this.phoneFlag = true;
  140. if (this.codeFlag) {
  141. this.codeLoginDisabled = false;
  142. }
  143. }
  144. if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phoneStr))) {
  145. this.codeColor = "#808080";
  146. this.getCodeFlag = false;
  147. this.phoneFlag = false;
  148. this.codeLoginDisabled = true;
  149. }
  150. },
  151. codeInput(e) {
  152. if (e.detail.value != "") {
  153. this.codeFlag = true;
  154. if (this.phoneFlag) {
  155. this.codeLoginDisabled = false;
  156. }
  157. } else {
  158. this.codeFlag = false;
  159. this.codeLoginDisabled = true;
  160. }
  161. },
  162. getCode: function() {
  163. if (this.getCodeFlag) {
  164. console.log("获取验证码")
  165. } else {
  166. console.log("不能获取验证码")
  167. }
  168. },
  169. changeType: function(type) {
  170. if (type == "account") {
  171. this.accountIsShow = true;
  172. this.phoneIsShow = false;
  173. }
  174. if (type == "phone") {
  175. this.phoneIsShow = true;
  176. this.accountIsShow = false;
  177. }
  178. },
  179. goToIndex: function() {
  180. let _this = this;
  181. uni.request({
  182. url: 'http://49.4.78.143:8057/GyeeuserController/login?username=' + 'admin' + '&password=' + 'admin',
  183. data: {},
  184. method: 'GET',
  185. success: function(res) {
  186. console.log(res.data);
  187. if (res.data.code == 200) {
  188. _this.loginFalg = true;
  189. }
  190. },
  191. fail: () => {
  192. _this.tips = '网络错误,小程序端请检查合法域名';
  193. }
  194. });
  195. uni.switchTab({
  196. url: '/pages/index/Index'
  197. });
  198. console.log(this.username)
  199. },
  200. falseLogin: function() {
  201. if (this.username == 'admin' && this.password == 'admin') {
  202. this.setUsernamePassword();
  203. uni.switchTab({
  204. url: '/pages/index/Index'
  205. });
  206. } else {
  207. uni.showModal({
  208. content: '用户名密码输入错误,请核对'
  209. });
  210. this.username = '';
  211. this.password = '';
  212. }
  213. },
  214. setUsernamePassword: function() {
  215. uni.setStorageSync('gyeeusername', this.username);
  216. uni.setStorageSync('gyeepassword', this.password);
  217. this.setFingerPrintPassword();
  218. },
  219. setFingerPrintPassword: function() {
  220. uni.setStorageSync('fingerPrintname', this.username);
  221. uni.setStorageSync('fingerPrintpassword', this.password);
  222. },
  223. getFingerPrintPassword: function() {
  224. if (uni.getStorageSync('fingerPrintname') != '' && uni.getStorageSync('fingerPrintpassword') != '') {
  225. uni.switchTab({
  226. url: '/pages/index/Index'
  227. });
  228. } else {
  229. uni.showToast({
  230. title: "请先用密码登录!"
  231. });
  232. }
  233. },
  234. getUsernamePassword: function() {
  235. this.lastUserName = uni.getStorageSync('gyeeusername');
  236. this.lastPassWord = uni.getStorageSync('gyeepassword');
  237. if (this.lastUserName != '' && this.lastPassWord != '') {
  238. uni.switchTab({
  239. url: '/pages/index/Index'
  240. });
  241. }
  242. },
  243. removeUsernamePassword: function() {
  244. uni.removeStorageSync('gyeeusername');
  245. uni.removeStorageSync('gyeepassword');
  246. },
  247. login: function() {
  248. let _this = this;
  249. uni.request({
  250. url: 'http://' + this.backStageIp + ':' + this.backStagePort + '/GyeeuserController/login?username=' + this.username +
  251. '&password=' + this.password,
  252. data: {},
  253. method: 'GET',
  254. success: function(res) {
  255. console.log(res.data);
  256. console.log(this.backStageIp)
  257. if (res.data.code == 200) {
  258. _this.setUsernamePassword();
  259. _this.loginFalg = true;
  260. _this.getUser();
  261. } else {
  262. uni.showModal({
  263. content: '用户名密码输入错误,请核对'
  264. });
  265. _this.username = '';
  266. _this.password = '';
  267. }
  268. },
  269. fail: () => {
  270. _this.tips = '网络错误,小程序端请检查合法域名';
  271. }
  272. });
  273. },
  274. getUser: function() {
  275. let _this = this;
  276. uni.request({
  277. url: 'http://49.4.78.143:8081/UserauthorityController/getUserSession',
  278. data: {},
  279. method: 'GET',
  280. success: function(res) {
  281. _this.lastUserName = res.data[0];
  282. _this.lastPassWord = res.data[1];
  283. _this.getWindPowerStation();
  284. },
  285. fail: () => {
  286. _this.tips = '网络错误,小程序端请检查合法域名';
  287. }
  288. });
  289. },
  290. getWindPowerStation: function() {
  291. let _this = this;
  292. uni.request({
  293. url: 'http://49.4.78.143:8081/UserauthorityController/selectuserauthority?userName=' + this.lastUserName +
  294. '&password=' + this.lastPassWord,
  295. data: {},
  296. method: 'GET',
  297. success: function(res) {
  298. _this.windPowerStations = res.data;
  299. //console.log(_this.windPowerStations);
  300. _this.windPowerStationId = _this.windPowerStations[0];
  301. if (_this.loginFalg) {
  302. if (_this.windPowerStationId == 'MHS_FDC') {
  303. _this.windpowerstationName = '麻黄山';
  304. }
  305. if (_this.windPowerStationId == 'NSS_FDC') {
  306. _this.windpowerstationName = '牛首山';
  307. }
  308. if (_this.windPowerStationId == 'XS_FDC') {
  309. _this.windpowerstationName = '香山';
  310. }
  311. if (_this.windPowerStationId == 'SBQ_FDC') {
  312. _this.windpowerstationName = '石板泉';
  313. }
  314. if (_this.windPowerStationId == 'QS_FDC') {
  315. _this.windpowerstationName = '青山';
  316. }
  317. if (_this.windPowerStationId == 'CL_FDC') {
  318. _this.windpowerstationName = '崇礼';
  319. }
  320. if (_this.windPowerStationId == 'KB_FDC') {
  321. _this.windpowerstationName = '康保';
  322. }
  323. if (_this.windPowerStationId == 'YMG_FDC') {
  324. _this.windpowerstationName = '雁门关';
  325. }
  326. if (_this.windPowerStationId == 'TY_FDC') {
  327. _this.windpowerstationName = '天源';
  328. }
  329. if (_this.windPowerStationId == 'AL_FDC') {
  330. _this.windpowerstationName = '熬伦';
  331. }
  332. if (_this.windPowerStationId == 'DBS_FDC') {
  333. _this.windpowerstationName = '调兵山';
  334. }
  335. if (_this.windPowerStationId == 'BZ_FDC') {
  336. _this.windpowerstationName = '北镇';
  337. }
  338. if (_this.windPowerStationId == 'XC_FDC') {
  339. _this.windpowerstationName = '兴城';
  340. }
  341. if (_this.windPowerStationId == 'FS_FDC') {
  342. _this.windpowerstationName = '芳山';
  343. }
  344. if (_this.windPowerStationId == 'LH_FDC') {
  345. _this.windpowerstationName = '凌海';
  346. }
  347. if (_this.windPowerStationId == 'XBQ_FDC') {
  348. _this.windpowerstationName = '西八千';
  349. }
  350. if (_this.windPowerStationId == 'TZS_FDC') {
  351. _this.windpowerstationName = '台子山';
  352. }
  353. if (_this.windPowerStationId == 'YM_FDC') {
  354. _this.windpowerstationName = '永茂';
  355. }
  356. if (_this.windPowerStationId == 'WF_FDC') {
  357. _this.windpowerstationName = '万发';
  358. }
  359. } else {
  360. _this.windpowerstationName = '游客身份浏览';
  361. }
  362. _this.pushWindPowerStationNameToSessionStorage(_this.windpowerstationName);
  363. },
  364. fail: () => {
  365. _this.tips = '网络错误,小程序端请检查合法域名';
  366. }
  367. });
  368. },
  369. pushWindPowerStationNameToSessionStorage(windpowerstationName) {
  370. uni.setStorageSync('windpowerstationName', windpowerstationName);
  371. uni.setStorageSync('windpowerstationNames', JSON.stringify(this.windPowerStations));
  372. uni.setStorageSync('windPowerStationId', this.windPowerStationId);
  373. uni.switchTab({
  374. url: '/pages/index/Index'
  375. });
  376. //sessionStorage.setItem('windpowerstationName', windpowerstationName);
  377. //alert("v"+ sessionStorage.getItem("windpowerstationName"));
  378. //this.common.goback('/pages/index/Index');
  379. },
  380. noLogin: function() {
  381. let _this = this;
  382. uni.request({
  383. url: 'http://49.4.78.143:8081/admin/appLogin?username=abc&password=123',
  384. data: {},
  385. method: 'GET',
  386. success: function(res) {
  387. console.log(res.data);
  388. if (res.data.code == 200) {
  389. _this.loginFalg = false;
  390. _this.getUser();
  391. }
  392. },
  393. fail: () => {
  394. _this.tips = '网络错误,小程序端请检查合法域名';
  395. }
  396. });
  397. },
  398. checkIsSoterEnrolledInDeviceFingerPrint() {
  399. let _this = this;
  400. uni.checkIsSoterEnrolledInDevice({
  401. checkAuthMode: 'fingerPrint',
  402. success(res) {
  403. uni.startSoterAuthentication({
  404. requestAuthModes: ['fingerPrint'],
  405. challenge: '123456',
  406. authContent: '请用指纹解锁',
  407. success(result) {
  408. if (result.errMsg == "startSoterAuthentication:ok") {
  409. //_this.setUsernamePassword();
  410. //_this.loginFalg = true;
  411. //_this.getUser()
  412. _this.getFingerPrintPassword();
  413. } else {
  414. uni.showToast({
  415. title: "指纹登录失败!"
  416. });
  417. _this.username = '';
  418. _this.password = '';
  419. }
  420. },
  421. fail(err) {
  422. console.log(err);
  423. },
  424. complete(res) {
  425. console.log(res);
  426. }
  427. })
  428. },
  429. fail(err) {
  430. uni.showToast({
  431. title: "请用手机指纹管理功能新建指纹录!"
  432. });
  433. },
  434. complete(res) {
  435. console.log(res);
  436. }
  437. })
  438. }
  439. }
  440. };
  441. </script>
  442. <style>
  443. page {
  444. height: 100%;
  445. /* background: -webkit-gradient(linear, 0% 100%, 0% 0%, from(#2f698e), color-stop(0.15, #5c757c), to(#004c90)); */
  446. }
  447. .title {
  448. width: 90%;
  449. height: 100px;
  450. font-size: 25px;
  451. font-weight: bold;
  452. padding-top: 50px;
  453. /* margin-top: 80px; */
  454. margin-left: 10%;
  455. }
  456. .usernameAndPassword {
  457. width: 100%;
  458. height: 100px;
  459. margin-top: 50px;
  460. }
  461. .usernameContent {
  462. width: 80%;
  463. margin-left: 10%;
  464. border-bottom: 2upx solid #D3D3D3;
  465. }
  466. .passwordContent {
  467. width: 80%;
  468. display: flex;
  469. align-items: center;
  470. justify-content: space-between;
  471. border-bottom: 2upx solid #D3D3D3;
  472. margin-top: 20px;
  473. margin-left: 10%;
  474. }
  475. input {
  476. width: 100%;
  477. height: 30px;
  478. }
  479. .type {
  480. width: 80%;
  481. height: 20px;
  482. line-height: 20px;
  483. margin-left: 10%;
  484. }
  485. .cu-btn {
  486. width: 80%;
  487. height: 40px;
  488. margin-left: 10%;
  489. margin-top: 25px;
  490. }
  491. .phoneContent {
  492. width: 80%;
  493. margin-left: 10%;
  494. border-bottom: 2upx solid #D3D3D3;
  495. display: flex;
  496. }
  497. .phoneContent span {
  498. line-height: 30px;
  499. margin-right: 5px;
  500. }
  501. .codeContent {
  502. width: 80%;
  503. margin-left: 10%;
  504. border-bottom: 2upx solid #D3D3D3;
  505. display: flex;
  506. margin-top: 20px;
  507. }
  508. .codeContent span {
  509. width: 100px;
  510. }
  511. .bottomWord {
  512. width: 80%;
  513. margin-left: 10%;
  514. color: #808080;
  515. font-size: 13px;
  516. margin-top: 270px;
  517. text-align: center;
  518. }
  519. a {
  520. text-decoration: none;
  521. }
  522. .bottomWord a:link {
  523. color: #5C97E4;
  524. }
  525. .bottomWord a:hover {
  526. color: #5C97E4;
  527. }
  528. .bottomWord a:visited {
  529. color: #5C97E4;
  530. }
  531. .bottomWord a:active {
  532. color: #5C97E4;
  533. }
  534. /* .container {
  535. border-radius: 20px;
  536. width: 90%;
  537. height: 700upx;
  538. margin: 0px auto;
  539. position: absolute;
  540. top: 20%;
  541. left: 5%;
  542. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024f93), color-stop(1.5, #cccccc), to(#437193));
  543. background: rgba(0, 0, 0, 0.1);
  544. }
  545. .title {
  546. width: 100%;
  547. height: 50px;
  548. color: white;
  549. line-height: 50px;
  550. text-align: center;
  551. margin-top: 5%;
  552. }
  553. .usernameContainer {
  554. width: 100%;
  555. height: 40px;
  556. line-height: 40px;
  557. margin-top: 10%;
  558. }
  559. .usernameContainer span {
  560. float: left;
  561. font-size: 18px;
  562. color: white;
  563. margin-left: 10px;
  564. }
  565. .username {
  566. width: 70%;
  567. height: 40px;
  568. border: 1px solid white;
  569. float: left;
  570. border-radius: 5px;
  571. }
  572. .passwordContainer {
  573. width: 100%;
  574. height: 40px;
  575. line-height: 40px;
  576. margin-top: 10%;
  577. }
  578. .passwordContainer span {
  579. float: left;
  580. font-size: 18px;
  581. color: white;
  582. margin-left: 10px;
  583. }
  584. .password {
  585. width: 70%;
  586. height: 40px;
  587. border: 1px solid white;
  588. float: left;
  589. border-radius: 5px;
  590. }
  591. .noLogin {
  592. width: calc(70% + 84px);
  593. height: 40px;
  594. text-align: right;
  595. color: white;
  596. //margin-left:15% ;
  597. //margin-right: 10px;
  598. line-height: 40px;
  599. }
  600. .noLogin a:link {
  601. color: white;
  602. }
  603. .noLogin a:hover {
  604. color: white;
  605. }
  606. .noLogin a:visited {
  607. color: white;
  608. }
  609. .noLogin a:active {
  610. color: white;
  611. }
  612. .cu-btn {
  613. width: 80%;
  614. height: 50px;
  615. margin-left: 10%;
  616. //margin-top: 10%;
  617. } */
  618. </style>