Login.vue 16 KB

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