Login.vue 13 KB

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