Login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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.switchTab({
  219. url: '/pages/index/Index'
  220. });
  221. }else
  222. {
  223. uni.showToast({
  224. title:"请先用密码登录!"
  225. });
  226. }
  227. },
  228. getUsernamePassword: function() {
  229. this.lastUserName = uni.getStorageSync('gyeeusername');
  230. this.lastPassWord = uni.getStorageSync('gyeepassword');
  231. if (this.lastUserName != '' && this.lastPassWord != '') {
  232. uni.switchTab({
  233. url: '/pages/index/Index'
  234. });
  235. }
  236. },
  237. removeUsernamePassword: function() {
  238. uni.removeStorageSync('gyeeusername');
  239. uni.removeStorageSync('gyeepassword');
  240. //uni.removeStorageSync('userid');
  241. },
  242. login: function() {
  243. let _this = this;
  244. uni.request({
  245. url: 'http://' + this.backStageIp + ':' + this.backStagePort + '/GyeeuserController/login?username=' + this.username + '&password=' + this.password,
  246. data: {},
  247. method: 'GET',
  248. success: function(res) {
  249. console.log(res.data);
  250. _this.userid = res.data.data;
  251. uni.setStorageSync('userid',_this.userid);
  252. //sessionStorage.setItem('userid',_this.userid);
  253. if (res.data.code == 200) {
  254. _this.dataprocessing.putWindPowerStationId(_this.$store.state.default_wpid);
  255. _this.dataprocessing.putWindPowerStationName(_this.$store.state.default_wpname);
  256. // if(_this.dataprocessing.getWindPowerStationId()=='')
  257. // {
  258. // //debugger
  259. // _this.dataprocessing.putWindPowerStationId(_this.$store.state.default_wpid);
  260. // }
  261. // if(_this.dataprocessing.getWindPowerStationName()=='')
  262. // {
  263. // //debugger
  264. // _this.dataprocessing.putWindPowerStationName(_this.$store.state.default_wpname);
  265. // }
  266. _this.setUsernamePassword();
  267. _this.loginFalg = true;
  268. _this.lastUserName = _this.username;
  269. _this.lastPassWord = _this.password;
  270. uni.switchTab({
  271. url: '/pages/index/Index'
  272. });
  273. } else {
  274. uni.showModal({
  275. content: '用户名密码输入错误,请核对'
  276. });
  277. _this.username = '';
  278. _this.password = '';
  279. }
  280. },
  281. fail: () => {
  282. _this.tips = '网络错误,小程序端请检查合法域名';
  283. }
  284. });
  285. },checkIsSoterEnrolledInDeviceFingerPrint() {
  286. let _this = this;
  287. uni.checkIsSoterEnrolledInDevice({
  288. checkAuthMode: 'fingerPrint',
  289. success(res) {
  290. uni.startSoterAuthentication({
  291. requestAuthModes: ['fingerPrint'],
  292. challenge: '123456',
  293. authContent: '请用指纹解锁',
  294. success(result) {
  295. if(result.errMsg=="startSoterAuthentication:ok")
  296. {
  297. //_this.setUsernamePassword();
  298. //_this.loginFalg = true;
  299. //_this.getUser()
  300. _this.getFingerPrintPassword();
  301. }else {
  302. uni.showToast({
  303. title:"指纹登录失败!"
  304. });
  305. _this.username = '';
  306. _this.password = '';
  307. }
  308. },
  309. fail(err) {
  310. console.log(err);
  311. },
  312. complete(res) {
  313. console.log(res);
  314. }
  315. })
  316. },
  317. fail(err) {
  318. uni.showToast({
  319. title:"请用手机指纹管理功能新建指纹录!"
  320. });
  321. },
  322. complete(res) {
  323. console.log(res);
  324. }
  325. })
  326. }
  327. }
  328. };
  329. </script>
  330. <style>
  331. page {
  332. background-color: #FFFFFF;
  333. height: 100%;
  334. /* background: -webkit-gradient(linear, 0% 100%, 0% 0%, from(#2f698e), color-stop(0.15, #5c757c), to(#004c90)); */
  335. }
  336. .title {
  337. width: 90%;
  338. height: 100px;
  339. font-size: 25px;
  340. font-weight: bold;
  341. padding-top: 50px;
  342. /* margin-top: 80px; */
  343. margin-left: 10%;
  344. }
  345. .usernameAndPassword {
  346. width: 100%;
  347. height: 100px;
  348. margin-top: 50px;
  349. }
  350. .usernameContent {
  351. width: 80%;
  352. margin-left: 10%;
  353. border-bottom: 2upx solid #D3D3D3;
  354. }
  355. .passwordContent {
  356. width: 80%;
  357. display: flex;
  358. align-items: center;
  359. justify-content: space-between;
  360. border-bottom: 2upx solid #D3D3D3;
  361. margin-top: 20px;
  362. margin-left: 10%;
  363. }
  364. input {
  365. width: 100%;
  366. height: 30px;
  367. }
  368. .type{
  369. width: 80%;
  370. height: 20px;
  371. line-height: 20px;
  372. margin-left: 10%;
  373. }
  374. .cu-btn {
  375. width: 80%;
  376. height: 40px;
  377. margin-left: 10%;
  378. margin-top: 25px;
  379. }
  380. .phoneContent{
  381. width: 80%;
  382. margin-left: 10%;
  383. border-bottom: 2upx solid #D3D3D3;
  384. display: flex;
  385. }
  386. .phoneContent span{
  387. line-height: 30px;
  388. margin-right: 5px;
  389. }
  390. .codeContent{
  391. width: 80%;
  392. margin-left: 10%;
  393. border-bottom: 2upx solid #D3D3D3;
  394. display: flex;
  395. margin-top: 20px;
  396. }
  397. .codeContent span{
  398. width: 100px;
  399. }
  400. .bottomWord{
  401. width: 80%;
  402. margin-left: 10%;
  403. color: #808080;
  404. font-size: 13px;
  405. margin-top: 270px;
  406. text-align: center;
  407. }
  408. a{
  409. text-decoration: none;
  410. }
  411. .bottomWord a:link {
  412. color: #5C97E4;
  413. }
  414. .bottomWord a:hover {
  415. color: #5C97E4;
  416. }
  417. .bottomWord a:visited {
  418. color: #5C97E4;
  419. }
  420. .bottomWord a:active {
  421. color: #5C97E4;
  422. }
  423. /* .container {
  424. border-radius: 20px;
  425. width: 90%;
  426. height: 700upx;
  427. margin: 0px auto;
  428. position: absolute;
  429. top: 20%;
  430. left: 5%;
  431. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024f93), color-stop(1.5, #cccccc), to(#437193));
  432. background: rgba(0, 0, 0, 0.1);
  433. }
  434. .title {
  435. width: 100%;
  436. height: 50px;
  437. color: white;
  438. line-height: 50px;
  439. text-align: center;
  440. margin-top: 5%;
  441. }
  442. .usernameContainer {
  443. width: 100%;
  444. height: 40px;
  445. line-height: 40px;
  446. margin-top: 10%;
  447. }
  448. .usernameContainer span {
  449. float: left;
  450. font-size: 18px;
  451. color: white;
  452. margin-left: 10px;
  453. }
  454. .username {
  455. width: 70%;
  456. height: 40px;
  457. border: 1px solid white;
  458. float: left;
  459. border-radius: 5px;
  460. }
  461. .passwordContainer {
  462. width: 100%;
  463. height: 40px;
  464. line-height: 40px;
  465. margin-top: 10%;
  466. }
  467. .passwordContainer span {
  468. float: left;
  469. font-size: 18px;
  470. color: white;
  471. margin-left: 10px;
  472. }
  473. .password {
  474. width: 70%;
  475. height: 40px;
  476. border: 1px solid white;
  477. float: left;
  478. border-radius: 5px;
  479. }
  480. .noLogin {
  481. width: calc(70% + 84px);
  482. height: 40px;
  483. text-align: right;
  484. color: white;
  485. //margin-left:15% ;
  486. //margin-right: 10px;
  487. line-height: 40px;
  488. }
  489. .noLogin a:link {
  490. color: white;
  491. }
  492. .noLogin a:hover {
  493. color: white;
  494. }
  495. .noLogin a:visited {
  496. color: white;
  497. }
  498. .noLogin a:active {
  499. color: white;
  500. }
  501. .cu-btn {
  502. width: 80%;
  503. height: 50px;
  504. margin-left: 10%;
  505. //margin-top: 10%;
  506. } */
  507. </style>