Login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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. </view>
  17. <button class="cu-btn bg-red lg" @tap="falseLogin" :disabled="usernameLoginDisabled" type="" :style="{ 'height': buttonHeight}">登录</button>
  18. <view class="bottomWord" :style="{ 'font-size': bottomWordFontSize,'margin-top':bottomWordMarginTop}">
  19. 点击登录,即代表已阅读并同意<a href="#">隐私政策</a>和<a href="#">用户协议</a>
  20. </view>
  21. </view>
  22. <view v-show="phoneIsShow">
  23. <view class="title">手机验证码登录</view>
  24. <view class="usernameAndPassword">
  25. <view class="phoneContent">
  26. <span>+86</span>
  27. <input type="text" v-model="phone" placeholder="请输入手机号码" @input="phoneInput" />
  28. </view>
  29. <view class="codeContent">
  30. <input type="text" v-model="code" placeholder="请输入验证码" @input="codeInput"/>
  31. <span :style="{ 'color': codeColor,'width':codeWidth }" @tap="getCode">获取验证码</span>
  32. </view>
  33. </view>
  34. <view class="type" :style="{ 'margin-top': typeMarginTop }">
  35. <a @tap="changeType('account')">账号登录</a>
  36. </view>
  37. <button class="cu-btn bg-red lg" :disabled="codeLoginDisabled" type="" :style="{ 'height': buttonHeight}">登录</button>
  38. <view class="bottomWord" :style="{ 'font-size': bottomWordFontSize,'margin-top':bottomWordMarginTop}">
  39. 点击登录,即代表已阅读并同意<a href="#">隐私政策</a>和<a href="#">用户协议</a>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. data: function() {
  47. return {
  48. passwordShow: true,
  49. accountIsShow:true,
  50. phoneIsShow:false,
  51. usernameLoginDisabled:true,
  52. codeLoginDisabled:true,
  53. username: '',
  54. password: '',
  55. phone:"",
  56. code:"",
  57. codeColor:"#808080",
  58. usernameFlag:false,
  59. passwordFlag:false,
  60. phoneFlag:false,
  61. codeFlag:false,
  62. getCodeFlag:false,
  63. lastUserName: '',
  64. lastPassWord: '',
  65. windowWidth:"",
  66. windowHeight:"",
  67. typeMarginTop:"",
  68. codeWidth:"",
  69. bottomWordFontSize:"",
  70. bottomWordMarginTop:"",
  71. buttonHeight:""
  72. };
  73. },
  74. created() {
  75. this.windowWidth = uni.getSystemInfoSync().windowWidth;
  76. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  77. //console.log(this.windowWidth);
  78. if (this.windowWidth >= 768) {
  79. this.typeMarginTop="10%";
  80. this.codeWidth="200px";
  81. this.bottomWordFontSize="18px";
  82. this.bottomWordMarginTop="500px";
  83. this.buttonHeight="50px";
  84. } else {
  85. this.typeMarginTop="0";
  86. this.codeWidth="100px";
  87. this.bottomWordFontSize="13px";
  88. this.bottomWordMarginTop="270px";
  89. this.buttonHeight="40px";
  90. }
  91. //this.removeUsernamePassword();
  92. this.getUsernamePassword();
  93. },
  94. methods: {
  95. showPass(e) {
  96. this.passwordShow = e;
  97. },
  98. usernameInput(e){
  99. if(e.detail.value!=""){
  100. this.usernameFlag=true;
  101. if(this.passwordFlag){
  102. this.usernameLoginDisabled=false;
  103. }
  104. }else{
  105. this.usernameFlag=false;
  106. this.usernameLoginDisabled=true;
  107. }
  108. },
  109. passwordInput(e){
  110. if(e.detail.value!=""){
  111. this.passwordFlag=true;
  112. if(this.usernameFlag){
  113. this.usernameLoginDisabled=false;
  114. }
  115. }else{
  116. this.passwordFlag=false;
  117. this.usernameLoginDisabled=true;
  118. }
  119. },
  120. phoneInput(e){
  121. // console.log(e.detail.value)
  122. var phoneStr = e.detail.value;
  123. if(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phoneStr)){
  124. this.codeColor="black";
  125. this.getCodeFlag=true;
  126. this.phoneFlag=true;
  127. if(this.codeFlag){
  128. this.codeLoginDisabled=false;
  129. }
  130. }
  131. if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phoneStr))){
  132. this.codeColor="#808080";
  133. this.getCodeFlag=false;
  134. this.phoneFlag=false;
  135. this.codeLoginDisabled=true;
  136. }
  137. },
  138. codeInput(e){
  139. if(e.detail.value!=""){
  140. this.codeFlag=true;
  141. if(this.phoneFlag){
  142. this.codeLoginDisabled=false;
  143. }
  144. }else{
  145. this.codeFlag=false;
  146. this.codeLoginDisabled=true;
  147. }
  148. },
  149. getCode:function(){
  150. if(this.getCodeFlag){
  151. console.log("获取验证码")
  152. }else{
  153. console.log("不能获取验证码")
  154. }
  155. },
  156. changeType:function(type){
  157. if(type=="account"){
  158. this.accountIsShow=true;
  159. this.phoneIsShow=false;
  160. }
  161. if(type=="phone"){
  162. this.phoneIsShow=true;
  163. this.accountIsShow=false;
  164. }
  165. },
  166. falseLogin: function() {
  167. if (this.username == 'abc' && this.password == '123') {
  168. this.setUsernamePassword();
  169. uni.switchTab({
  170. url: '/pages/index/Index'
  171. });
  172. }else{
  173. uni.showModal({
  174. content: '用户名密码输入错误,请核对'
  175. });
  176. this.username = '';
  177. this.password = '';
  178. }
  179. },
  180. setUsernamePassword: function() {
  181. uni.setStorageSync('gyeeusername', this.username);
  182. uni.setStorageSync('gyeepassword', this.password);
  183. },
  184. getUsernamePassword: function() {
  185. this.lastUserName = uni.getStorageSync('gyeeusername');
  186. this.lastPassWord = uni.getStorageSync('gyeepassword');
  187. if (this.lastUserName != '' && this.lastPassWord != '') {
  188. uni.switchTab({
  189. url: '/pages/index/Index'
  190. });
  191. }
  192. },
  193. removeUsernamePassword: function() {
  194. uni.removeStorageSync('gyeeusername');
  195. uni.removeStorageSync('gyeepassword');
  196. },
  197. login: function() {
  198. let _this = this;
  199. uni.request({
  200. url: 'http://49.4.78.143:8081/admin/appLogin?username=' + this.username + '&password=' + this.password,
  201. data: {},
  202. method: 'GET',
  203. success: function(res) {
  204. console.log(res.data);
  205. if (res.data.code == 200) {
  206. _this.loginFalg = true;
  207. _this.getUser();
  208. } else {
  209. uni.showModal({
  210. content: '用户名密码输入错误,请核对'
  211. });
  212. _this.username = '';
  213. _this.password = '';
  214. }
  215. },
  216. fail: () => {
  217. _this.tips = '网络错误,小程序端请检查合法域名';
  218. }
  219. });
  220. },
  221. getUser: function() {
  222. let _this = this;
  223. uni.request({
  224. url: 'http://49.4.78.143:8081/UserauthorityController/getUserSession',
  225. data: {},
  226. method: 'GET',
  227. success: function(res) {
  228. _this.lastUserName = res.data[0];
  229. _this.lastPassWord = res.data[1];
  230. _this.getWindPowerStation();
  231. },
  232. fail: () => {
  233. _this.tips = '网络错误,小程序端请检查合法域名';
  234. }
  235. });
  236. },
  237. getWindPowerStation: function() {
  238. let _this = this;
  239. uni.request({
  240. url: 'http://49.4.78.143:8081/UserauthorityController/selectuserauthority?userName=' + this.lastUserName + '&password=' + this.lastPassWord,
  241. data: {},
  242. method: 'GET',
  243. success: function(res) {
  244. _this.windPowerStations = res.data;
  245. //console.log(_this.windPowerStations);
  246. _this.windPowerStationId = _this.windPowerStations[0];
  247. if (_this.loginFalg) {
  248. if (_this.windPowerStationId == 'MHS_FDC') {
  249. _this.windpowerstationName = '麻黄山';
  250. }
  251. if (_this.windPowerStationId == 'NSS_FDC') {
  252. _this.windpowerstationName = '牛首山';
  253. }
  254. if (_this.windPowerStationId == 'XS_FDC') {
  255. _this.windpowerstationName = '香山';
  256. }
  257. if (_this.windPowerStationId == 'SBQ_FDC') {
  258. _this.windpowerstationName = '石板泉';
  259. }
  260. if (_this.windPowerStationId == 'QS_FDC') {
  261. _this.windpowerstationName = '青山';
  262. }
  263. if (_this.windPowerStationId == 'CL_FDC') {
  264. _this.windpowerstationName = '崇礼';
  265. }
  266. if (_this.windPowerStationId == 'KB_FDC') {
  267. _this.windpowerstationName = '康保';
  268. }
  269. if (_this.windPowerStationId == 'YMG_FDC') {
  270. _this.windpowerstationName = '雁门关';
  271. }
  272. if (_this.windPowerStationId == 'TY_FDC') {
  273. _this.windpowerstationName = '天源';
  274. }
  275. if (_this.windPowerStationId == 'AL_FDC') {
  276. _this.windpowerstationName = '熬伦';
  277. }
  278. if (_this.windPowerStationId == 'DBS_FDC') {
  279. _this.windpowerstationName = '调兵山';
  280. }
  281. if (_this.windPowerStationId == 'BZ_FDC') {
  282. _this.windpowerstationName = '北镇';
  283. }
  284. if (_this.windPowerStationId == 'XC_FDC') {
  285. _this.windpowerstationName = '兴城';
  286. }
  287. if (_this.windPowerStationId == 'FS_FDC') {
  288. _this.windpowerstationName = '芳山';
  289. }
  290. if (_this.windPowerStationId == 'LH_FDC') {
  291. _this.windpowerstationName = '凌海';
  292. }
  293. if (_this.windPowerStationId == 'XBQ_FDC') {
  294. _this.windpowerstationName = '西八千';
  295. }
  296. if (_this.windPowerStationId == 'TZS_FDC') {
  297. _this.windpowerstationName = '台子山';
  298. }
  299. if (_this.windPowerStationId == 'YM_FDC') {
  300. _this.windpowerstationName = '永茂';
  301. }
  302. if (_this.windPowerStationId == 'WF_FDC') {
  303. _this.windpowerstationName = '万发';
  304. }
  305. } else {
  306. _this.windpowerstationName = '游客身份浏览';
  307. }
  308. _this.pushWindPowerStationNameToSessionStorage(_this.windpowerstationName);
  309. },
  310. fail: () => {
  311. _this.tips = '网络错误,小程序端请检查合法域名';
  312. }
  313. });
  314. },
  315. pushWindPowerStationNameToSessionStorage(windpowerstationName) {
  316. uni.setStorageSync('windpowerstationName', windpowerstationName);
  317. uni.setStorageSync('windpowerstationNames', JSON.stringify(this.windPowerStations));
  318. uni.setStorageSync('windPowerStationId', this.windPowerStationId);
  319. uni.switchTab({
  320. url: '/pages/index/Index'
  321. });
  322. //sessionStorage.setItem('windpowerstationName', windpowerstationName);
  323. //alert("v"+ sessionStorage.getItem("windpowerstationName"));
  324. //this.common.goback('/pages/index/Index');
  325. },
  326. noLogin: function() {
  327. let _this = this;
  328. uni.request({
  329. url: 'http://49.4.78.143:8081/admin/appLogin?username=abc&password=123',
  330. data: {},
  331. method: 'GET',
  332. success: function(res) {
  333. console.log(res.data);
  334. if (res.data.code == 200) {
  335. _this.loginFalg = false;
  336. _this.getUser();
  337. }
  338. },
  339. fail: () => {
  340. _this.tips = '网络错误,小程序端请检查合法域名';
  341. }
  342. });
  343. }
  344. }
  345. };
  346. </script>
  347. <style>
  348. page {
  349. height: 100%;
  350. /* background: -webkit-gradient(linear, 0% 100%, 0% 0%, from(#2f698e), color-stop(0.15, #5c757c), to(#004c90)); */
  351. }
  352. .title {
  353. width: 90%;
  354. height: 100px;
  355. font-size: 25px;
  356. font-weight: bold;
  357. padding-top: 50px;
  358. /* margin-top: 80px; */
  359. margin-left: 10%;
  360. }
  361. .usernameAndPassword {
  362. width: 100%;
  363. height: 100px;
  364. margin-top: 50px;
  365. }
  366. .usernameContent {
  367. width: 80%;
  368. margin-left: 10%;
  369. border-bottom: 2upx solid #D3D3D3;
  370. }
  371. .passwordContent {
  372. width: 80%;
  373. display: flex;
  374. align-items: center;
  375. justify-content: space-between;
  376. border-bottom: 2upx solid #D3D3D3;
  377. margin-top: 20px;
  378. margin-left: 10%;
  379. }
  380. input {
  381. width: 100%;
  382. height: 30px;
  383. }
  384. .type{
  385. width: 80%;
  386. height: 20px;
  387. line-height: 20px;
  388. margin-left: 10%;
  389. }
  390. .cu-btn {
  391. width: 80%;
  392. height: 40px;
  393. margin-left: 10%;
  394. margin-top: 25px;
  395. }
  396. .phoneContent{
  397. width: 80%;
  398. margin-left: 10%;
  399. border-bottom: 2upx solid #D3D3D3;
  400. display: flex;
  401. }
  402. .phoneContent span{
  403. line-height: 30px;
  404. margin-right: 5px;
  405. }
  406. .codeContent{
  407. width: 80%;
  408. margin-left: 10%;
  409. border-bottom: 2upx solid #D3D3D3;
  410. display: flex;
  411. margin-top: 20px;
  412. }
  413. .codeContent span{
  414. width: 100px;
  415. }
  416. .bottomWord{
  417. width: 80%;
  418. margin-left: 10%;
  419. color: #808080;
  420. font-size: 13px;
  421. margin-top: 270px;
  422. text-align: center;
  423. }
  424. a{
  425. text-decoration: none;
  426. }
  427. .bottomWord a:link {
  428. color: #5C97E4;
  429. }
  430. .bottomWord a:hover {
  431. color: #5C97E4;
  432. }
  433. .bottomWord a:visited {
  434. color: #5C97E4;
  435. }
  436. .bottomWord a:active {
  437. color: #5C97E4;
  438. }
  439. /* .container {
  440. border-radius: 20px;
  441. width: 90%;
  442. height: 700upx;
  443. margin: 0px auto;
  444. position: absolute;
  445. top: 20%;
  446. left: 5%;
  447. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024f93), color-stop(1.5, #cccccc), to(#437193));
  448. background: rgba(0, 0, 0, 0.1);
  449. }
  450. .title {
  451. width: 100%;
  452. height: 50px;
  453. color: white;
  454. line-height: 50px;
  455. text-align: center;
  456. margin-top: 5%;
  457. }
  458. .usernameContainer {
  459. width: 100%;
  460. height: 40px;
  461. line-height: 40px;
  462. margin-top: 10%;
  463. }
  464. .usernameContainer span {
  465. float: left;
  466. font-size: 18px;
  467. color: white;
  468. margin-left: 10px;
  469. }
  470. .username {
  471. width: 70%;
  472. height: 40px;
  473. border: 1px solid white;
  474. float: left;
  475. border-radius: 5px;
  476. }
  477. .passwordContainer {
  478. width: 100%;
  479. height: 40px;
  480. line-height: 40px;
  481. margin-top: 10%;
  482. }
  483. .passwordContainer span {
  484. float: left;
  485. font-size: 18px;
  486. color: white;
  487. margin-left: 10px;
  488. }
  489. .password {
  490. width: 70%;
  491. height: 40px;
  492. border: 1px solid white;
  493. float: left;
  494. border-radius: 5px;
  495. }
  496. .noLogin {
  497. width: calc(70% + 84px);
  498. height: 40px;
  499. text-align: right;
  500. color: white;
  501. //margin-left:15% ;
  502. //margin-right: 10px;
  503. line-height: 40px;
  504. }
  505. .noLogin a:link {
  506. color: white;
  507. }
  508. .noLogin a:hover {
  509. color: white;
  510. }
  511. .noLogin a:visited {
  512. color: white;
  513. }
  514. .noLogin a:active {
  515. color: white;
  516. }
  517. .cu-btn {
  518. width: 80%;
  519. height: 50px;
  520. margin-left: 10%;
  521. //margin-top: 10%;
  522. } */
  523. </style>