Login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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. windpowerstationName: function() {
  108. return this.$store.state.default_wpname;
  109. },
  110. windpowerstationId: function() {
  111. return this.$store.state.default_wpid;
  112. }
  113. },
  114. methods: {
  115. showPass(e) {
  116. this.passwordShow = e;
  117. },
  118. usernameInput(e){
  119. if(e.detail.value!=""){
  120. this.usernameFlag=true;
  121. if(this.passwordFlag){
  122. this.usernameLoginDisabled=false;
  123. }
  124. }else{
  125. this.usernameFlag=false;
  126. this.usernameLoginDisabled=true;
  127. }
  128. },
  129. passwordInput(e){
  130. if(e.detail.value!=""){
  131. this.passwordFlag=true;
  132. if(this.usernameFlag){
  133. this.usernameLoginDisabled=false;
  134. }
  135. }else{
  136. this.passwordFlag=false;
  137. this.usernameLoginDisabled=true;
  138. }
  139. },
  140. phoneInput(e){
  141. // console.log(e.detail.value)
  142. var phoneStr = e.detail.value;
  143. if(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phoneStr)){
  144. this.codeColor="black";
  145. this.getCodeFlag=true;
  146. this.phoneFlag=true;
  147. if(this.codeFlag){
  148. this.codeLoginDisabled=false;
  149. }
  150. }
  151. if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phoneStr))){
  152. this.codeColor="#808080";
  153. this.getCodeFlag=false;
  154. this.phoneFlag=false;
  155. this.codeLoginDisabled=true;
  156. }
  157. },
  158. codeInput(e){
  159. if(e.detail.value!=""){
  160. this.codeFlag=true;
  161. if(this.phoneFlag){
  162. this.codeLoginDisabled=false;
  163. }
  164. }else{
  165. this.codeFlag=false;
  166. this.codeLoginDisabled=true;
  167. }
  168. },
  169. getCode:function(){
  170. if(this.getCodeFlag){
  171. console.log("获取验证码")
  172. }else{
  173. console.log("不能获取验证码")
  174. }
  175. },
  176. changeType:function(type){
  177. if(type=="account"){
  178. this.accountIsShow=true;
  179. this.phoneIsShow=false;
  180. }
  181. if(type=="phone"){
  182. this.phoneIsShow=true;
  183. this.accountIsShow=false;
  184. }
  185. },
  186. goToIndex:function(){
  187. let _this = this;
  188. _this.loginFalg = true;
  189. uni.switchTab({
  190. url: '/pages/index/Index'
  191. });
  192. },
  193. falseLogin: function() {
  194. if (this.username == 'admin' && this.password == 'admin') {
  195. this.setUsernamePassword();
  196. uni.switchTab({
  197. url: '/pages/index/Index'
  198. });
  199. }else{
  200. uni.showModal({
  201. content: '用户名密码输入错误,请核对'
  202. });
  203. this.username = '';
  204. this.password = '';
  205. }
  206. },
  207. setUsernamePassword: function() {
  208. uni.setStorageSync('gyeeusername', this.username);
  209. uni.setStorageSync('gyeepassword', this.password);
  210. this.setFingerPrintPassword();
  211. },
  212. setFingerPrintPassword: function() {
  213. uni.setStorageSync('fingerPrintname', this.username);
  214. uni.setStorageSync('fingerPrintpassword', this.password);
  215. },
  216. getFingerPrintPassword: function() {
  217. if (uni.getStorageSync('fingerPrintname') != '' && uni.getStorageSync('fingerPrintpassword') != '') {
  218. uni.setStorageSync('gyeeusername', uni.getStorageSync('fingerPrintname'));
  219. uni.setStorageSync('gyeepassword', uni.getStorageSync('fingerPrintpassword'));
  220. this.dataprocessing.viewUserid();
  221. this.dataprocessing.monitoringAuthority();
  222. uni.switchTab({
  223. url: '/pages/index/Index'
  224. });
  225. }else
  226. {
  227. uni.showToast({
  228. title:"请先用密码登录!"
  229. });
  230. }
  231. },
  232. getUsernamePassword: function() {
  233. this.lastUserName = uni.getStorageSync('gyeeusername');
  234. this.lastPassWord = uni.getStorageSync('gyeepassword');
  235. if (this.lastUserName != '' && this.lastPassWord != '') {
  236. uni.switchTab({
  237. url: '/pages/index/Index'
  238. });
  239. }
  240. },
  241. removeUsernamePassword: function() {
  242. uni.removeStorageSync('gyeeusername');
  243. uni.removeStorageSync('gyeepassword');
  244. //uni.removeStorageSync('userid');
  245. },
  246. login: function() {
  247. let _this = this;
  248. uni.request({
  249. url: 'http://' + this.backStageIp + ':' + this.backStagePort + '/GyeeuserController/login?username=' + this.username + '&password=' + this.password,
  250. data: {},
  251. method: 'GET',
  252. success: function(res) {
  253. console.log(res.data);
  254. _this.userid = res.data.data;
  255. uni.setStorageSync('userid',_this.userid);
  256. //sessionStorage.setItem('userid',_this.userid);
  257. if (res.data.code == 200) {
  258. _this.dataprocessing.putWindPowerStationId(_this.$store.state.default_wpid);
  259. _this.dataprocessing.putWindPowerStationName(_this.$store.state.default_wpname);
  260. _this.dataprocessing.viewUserid();
  261. _this.dataprocessing.monitoringAuthority();
  262. // if(_this.dataprocessing.getWindPowerStationId()=='')
  263. // {
  264. // //debugger
  265. // _this.dataprocessing.putWindPowerStationId(_this.$store.state.default_wpid);
  266. // }
  267. // if(_this.dataprocessing.getWindPowerStationName()=='')
  268. // {
  269. // //debugger
  270. // _this.dataprocessing.putWindPowerStationName(_this.$store.state.default_wpname);
  271. // }
  272. _this.setUsernamePassword();
  273. _this.loginFalg = true;
  274. _this.lastUserName = _this.username;
  275. _this.lastPassWord = _this.password;
  276. uni.switchTab({
  277. url: '/pages/index/Index'
  278. });
  279. } else {
  280. uni.showModal({
  281. content: '用户名密码输入错误,请核对'
  282. });
  283. _this.username = '';
  284. _this.password = '';
  285. }
  286. },
  287. fail: () => {
  288. _this.tips = '网络错误,小程序端请检查合法域名';
  289. }
  290. });
  291. },checkIsSoterEnrolledInDeviceFingerPrint() {
  292. let _this = this;
  293. uni.checkIsSoterEnrolledInDevice({
  294. checkAuthMode: 'fingerPrint',
  295. success(res) {
  296. uni.startSoterAuthentication({
  297. requestAuthModes: ['fingerPrint'],
  298. challenge: '123456',
  299. authContent: '请用指纹解锁',
  300. success(result) {
  301. if(result.errMsg=="startSoterAuthentication:ok")
  302. {
  303. //_this.setUsernamePassword();
  304. //_this.loginFalg = true;
  305. //_this.getUser()
  306. _this.getFingerPrintPassword();
  307. }else {
  308. uni.showToast({
  309. title:"指纹登录失败!"
  310. });
  311. _this.username = '';
  312. _this.password = '';
  313. }
  314. },
  315. fail(err) {
  316. console.log(err);
  317. },
  318. complete(res) {
  319. console.log(res);
  320. }
  321. })
  322. },
  323. fail(err) {
  324. uni.showToast({
  325. title:"请用手机指纹管理功能新建指纹录!"
  326. });
  327. },
  328. complete(res) {
  329. console.log(res);
  330. }
  331. })
  332. }
  333. }
  334. };
  335. </script>
  336. <style>
  337. page {
  338. background-color: #FFFFFF;
  339. height: 100%;
  340. /* background: -webkit-gradient(linear, 0% 100%, 0% 0%, from(#2f698e), color-stop(0.15, #5c757c), to(#004c90)); */
  341. }
  342. .title {
  343. width: 90%;
  344. height: 100px;
  345. font-size: 25px;
  346. font-weight: bold;
  347. padding-top: 50px;
  348. /* margin-top: 80px; */
  349. margin-left: 10%;
  350. }
  351. .usernameAndPassword {
  352. width: 100%;
  353. height: 100px;
  354. margin-top: 50px;
  355. }
  356. .usernameContent {
  357. width: 80%;
  358. margin-left: 10%;
  359. border-bottom: 2upx solid #D3D3D3;
  360. }
  361. .passwordContent {
  362. width: 80%;
  363. display: flex;
  364. align-items: center;
  365. justify-content: space-between;
  366. border-bottom: 2upx solid #D3D3D3;
  367. margin-top: 20px;
  368. margin-left: 10%;
  369. }
  370. input {
  371. width: 100%;
  372. height: 30px;
  373. }
  374. .type{
  375. width: 80%;
  376. height: 20px;
  377. line-height: 20px;
  378. margin-left: 10%;
  379. }
  380. .cu-btn {
  381. width: 80%;
  382. height: 40px;
  383. margin-left: 10%;
  384. margin-top: 25px;
  385. }
  386. .phoneContent{
  387. width: 80%;
  388. margin-left: 10%;
  389. border-bottom: 2upx solid #D3D3D3;
  390. display: flex;
  391. }
  392. .phoneContent span{
  393. line-height: 30px;
  394. margin-right: 5px;
  395. }
  396. .codeContent{
  397. width: 80%;
  398. margin-left: 10%;
  399. border-bottom: 2upx solid #D3D3D3;
  400. display: flex;
  401. margin-top: 20px;
  402. }
  403. .codeContent span{
  404. width: 100px;
  405. }
  406. .bottomWord{
  407. width: 80%;
  408. margin-left: 10%;
  409. color: #808080;
  410. font-size: 13px;
  411. margin-top: 270px;
  412. text-align: center;
  413. }
  414. a{
  415. text-decoration: none;
  416. }
  417. .bottomWord a:link {
  418. color: #5C97E4;
  419. }
  420. .bottomWord a:hover {
  421. color: #5C97E4;
  422. }
  423. .bottomWord a:visited {
  424. color: #5C97E4;
  425. }
  426. .bottomWord a:active {
  427. color: #5C97E4;
  428. }
  429. /* .container {
  430. border-radius: 20px;
  431. width: 90%;
  432. height: 700upx;
  433. margin: 0px auto;
  434. position: absolute;
  435. top: 20%;
  436. left: 5%;
  437. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024f93), color-stop(1.5, #cccccc), to(#437193));
  438. background: rgba(0, 0, 0, 0.1);
  439. }
  440. .title {
  441. width: 100%;
  442. height: 50px;
  443. color: white;
  444. line-height: 50px;
  445. text-align: center;
  446. margin-top: 5%;
  447. }
  448. .usernameContainer {
  449. width: 100%;
  450. height: 40px;
  451. line-height: 40px;
  452. margin-top: 10%;
  453. }
  454. .usernameContainer span {
  455. float: left;
  456. font-size: 18px;
  457. color: white;
  458. margin-left: 10px;
  459. }
  460. .username {
  461. width: 70%;
  462. height: 40px;
  463. border: 1px solid white;
  464. float: left;
  465. border-radius: 5px;
  466. }
  467. .passwordContainer {
  468. width: 100%;
  469. height: 40px;
  470. line-height: 40px;
  471. margin-top: 10%;
  472. }
  473. .passwordContainer span {
  474. float: left;
  475. font-size: 18px;
  476. color: white;
  477. margin-left: 10px;
  478. }
  479. .password {
  480. width: 70%;
  481. height: 40px;
  482. border: 1px solid white;
  483. float: left;
  484. border-radius: 5px;
  485. }
  486. .noLogin {
  487. width: calc(70% + 84px);
  488. height: 40px;
  489. text-align: right;
  490. color: white;
  491. //margin-left:15% ;
  492. //margin-right: 10px;
  493. line-height: 40px;
  494. }
  495. .noLogin a:link {
  496. color: white;
  497. }
  498. .noLogin a:hover {
  499. color: white;
  500. }
  501. .noLogin a:visited {
  502. color: white;
  503. }
  504. .noLogin a:active {
  505. color: white;
  506. }
  507. .cu-btn {
  508. width: 80%;
  509. height: 50px;
  510. margin-left: 10%;
  511. //margin-top: 10%;
  512. } */
  513. </style>