Login.vue 14 KB

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