Login.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view>
  3. <div class="container">
  4. <view class="title"><h3>云端气象采集预测</h3></view>
  5. <view class="usernameContainer" :style="{'margin-left':marginLeft}">
  6. <span :style="{'font-size':fontSize}">用户名:</span><input type="text" v-model="username" class="username"/>
  7. </view>
  8. <view class="passwordContainer" :style="{'margin-left':marginLeft}">
  9. <span :style="{'font-size':fontSize}">密&nbsp;&nbsp;&nbsp;&nbsp;码:</span><input type="password" v-model="password" class="password"/>
  10. </view>
  11. <view class="noLogin" :style="{'width':noLoginWidth,'font-size':noLoginFontSize,'margin-top':noLoginMarginTop}">
  12. <a href="#" @tap="noLogin">免登录,以游客身份浏览</a>
  13. </view>
  14. <button class="cu-btn bg-blue lg" @tap="login" :style="{'margin-top':loginMarginTop}">登录</button>
  15. </div>
  16. </view>
  17. </template>
  18. <script>
  19. export default{
  20. data:function(){
  21. return{
  22. username:"",
  23. password:"",
  24. lastUserName:"",
  25. lastPassWord:"",
  26. windPowerStations:[],
  27. windPowerStationId:"",
  28. windpowerstationName:"",
  29. windowWidth:"",
  30. windowHeight:"",
  31. fontSize:"",
  32. marginLeft:"",
  33. loginMarginTop:"",
  34. noLoginMarginTop:"",
  35. noLoginFontSize:"",
  36. loginFalg:false,
  37. noLoginWidth:""
  38. }
  39. },
  40. created() {
  41. this.windowWidth=uni.getSystemInfoSync().windowWidth;
  42. this.windowHeight=uni.getSystemInfoSync().windowHeight;
  43. //console.log(this.windowWidth);
  44. if(this.windowWidth>=768){
  45. this.fontSize="25px";
  46. this.marginLeft="5%";
  47. this.loginMarginTop="10%";
  48. this.noLoginMarginTop="5%";
  49. this.noLoginFontSize="22px";
  50. this.noLoginWidth="calc(70% + 147px)";
  51. }else{
  52. this.fontSize="18px";
  53. this.marginLeft="0";
  54. this.loginMarginTop="0";
  55. this.noLoginMarginTop="0";
  56. this.noLoginFontSize="14px";
  57. this.noLoginWidth="calc(70% + 84px)";
  58. }
  59. },
  60. methods:{
  61. login:function(){
  62. let _this=this;
  63. uni.request({
  64. url: 'http://49.4.78.143:8081/admin/appLogin?username='+this.username+'&password='+this.password,
  65. data:{
  66. },
  67. method:'GET',
  68. success: function(res) {
  69. console.log(res.data)
  70. if(res.data.code==200){
  71. _this.loginFalg=true;
  72. _this.getUser();
  73. }else{
  74. uni.showModal({
  75. content: '用户名密码输入错误,请核对',
  76. });
  77. _this.username="";
  78. _this.password="";
  79. }
  80. },
  81. fail: () => {
  82. _this.tips="网络错误,小程序端请检查合法域名";
  83. },
  84. });
  85. },
  86. getUser:function(){
  87. let _this=this;
  88. uni.request({
  89. url: 'http://49.4.78.143:8081/UserauthorityController/getUserSession',
  90. data:{
  91. },
  92. method:'GET',
  93. success: function(res) {
  94. _this.lastUserName=res.data[0];
  95. _this.lastPassWord=res.data[1];
  96. _this.getWindPowerStation();
  97. },
  98. fail: () => {
  99. _this.tips="网络错误,小程序端请检查合法域名";
  100. },
  101. });
  102. },
  103. getWindPowerStation:function(){
  104. let _this=this;
  105. uni.request({
  106. url: 'http://49.4.78.143:8081/UserauthorityController/selectuserauthority?userName='+this.lastUserName+'&password='+this.lastPassWord,
  107. data:{
  108. },
  109. method:'GET',
  110. success: function(res) {
  111. _this.windPowerStations=res.data;
  112. //console.log(_this.windPowerStations);
  113. _this.windPowerStationId=_this.windPowerStations[0];
  114. if(_this.loginFalg){
  115. if(_this.windPowerStationId=="MHS_FDC"){
  116. _this.windpowerstationName="麻黄山";
  117. }
  118. if(_this.windPowerStationId=="NSS_FDC"){
  119. _this.windpowerstationName="牛首山";
  120. }
  121. if(_this.windPowerStationId=="XS_FDC"){
  122. _this.windpowerstationName="香山";
  123. }
  124. if(_this.windPowerStationId=="SBQ_FDC"){
  125. _this.windpowerstationName="石板泉";
  126. }
  127. if(_this.windPowerStationId=="QS_FDC"){
  128. _this.windpowerstationName="青山";
  129. }
  130. if(_this.windPowerStationId=="CL_FDC"){
  131. _this.windpowerstationName="崇礼";
  132. }
  133. if(_this.windPowerStationId=="KB_FDC"){
  134. _this.windpowerstationName="康保";
  135. }
  136. if(_this.windPowerStationId=="YMG_FDC"){
  137. _this.windpowerstationName="雁门关";
  138. }
  139. if(_this.windPowerStationId=="TY_FDC"){
  140. _this.windpowerstationName="天源";
  141. }
  142. if(_this.windPowerStationId=="AL_FDC"){
  143. _this.windpowerstationName="熬伦";
  144. }
  145. if(_this.windPowerStationId=="DBS_FDC"){
  146. _this.windpowerstationName="调兵山";
  147. }
  148. if(_this.windPowerStationId=="BZ_FDC"){
  149. _this.windpowerstationName="北镇";
  150. }
  151. if(_this.windPowerStationId=="XC_FDC"){
  152. _this.windpowerstationName="兴城";
  153. }
  154. if(_this.windPowerStationId=="FS_FDC"){
  155. _this.windpowerstationName="芳山";
  156. }
  157. if(_this.windPowerStationId=="LH_FDC"){
  158. _this.windpowerstationName="凌海";
  159. }
  160. if(_this.windPowerStationId=="XBQ_FDC"){
  161. _this.windpowerstationName="西八千";
  162. }
  163. if(_this.windPowerStationId=="TZS_FDC"){
  164. _this.windpowerstationName="台子山";
  165. }
  166. if(_this.windPowerStationId=="YM_FDC"){
  167. _this.windpowerstationName="永茂";
  168. }
  169. if(_this.windPowerStationId=="WF_FDC"){
  170. _this.windpowerstationName="万发";
  171. }
  172. }else{
  173. _this.windpowerstationName="游客身份浏览";
  174. }
  175. _this.pushWindPowerStationNameToSessionStorage(_this.windpowerstationName);
  176. },
  177. fail: () => {
  178. _this.tips="网络错误,小程序端请检查合法域名";
  179. },
  180. });
  181. },
  182. pushWindPowerStationNameToSessionStorage(windpowerstationName) {
  183. uni.setStorageSync('windpowerstationName',windpowerstationName);
  184. uni.setStorageSync('windpowerstationNames',JSON.stringify(this.windPowerStations));
  185. uni.setStorageSync('windPowerStationId',this.windPowerStationId);
  186. uni.switchTab({
  187. url: '/pages/index/Index'
  188. });
  189. //sessionStorage.setItem('windpowerstationName', windpowerstationName);
  190. //alert("v"+ sessionStorage.getItem("windpowerstationName"));
  191. //this.common.goback('/pages/index/Index');
  192. },
  193. noLogin:function(){
  194. let _this=this;
  195. uni.request({
  196. url: 'http://49.4.78.143:8081/admin/appLogin?username=abc&password=123',
  197. data:{
  198. },
  199. method:'GET',
  200. success: function(res) {
  201. console.log(res.data)
  202. if(res.data.code==200){
  203. _this.loginFalg=false;
  204. _this.getUser();
  205. }
  206. },
  207. fail: () => {
  208. _this.tips="网络错误,小程序端请检查合法域名";
  209. },
  210. });
  211. }
  212. }
  213. }
  214. </script>
  215. <style>
  216. page {
  217. height: 100%;
  218. background: -webkit-gradient(linear, 0% 100%, 0% 0%, from(#2F698E), color-stop(0.15, #5C757C), to(#004C90));
  219. }
  220. .container{
  221. border-radius: 20px;
  222. width: 90%;
  223. height: 700upx;
  224. margin: 0px auto;
  225. position: absolute;
  226. top: 20%;
  227. left: 5%;
  228. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024F93), color-stop(1.5, #cccccc), to(#437193));
  229. background: rgba(0, 0, 0, 0.1);
  230. }
  231. .title{
  232. width: 100%;
  233. height: 50px;
  234. color: white;
  235. line-height: 50px;
  236. text-align: center;
  237. margin-top: 5%;
  238. }
  239. .usernameContainer{
  240. width: 100%;
  241. height: 40px;
  242. line-height: 40px;
  243. margin-top: 10%;
  244. }
  245. .usernameContainer span{
  246. float: left;
  247. font-size: 18px;
  248. color: white;
  249. margin-left: 10px;
  250. }
  251. .username{
  252. width: 70%;
  253. height: 40px;
  254. border: 1px solid white;
  255. float: left;
  256. border-radius: 5px;
  257. }
  258. .passwordContainer{
  259. width: 100%;
  260. height: 40px;
  261. line-height: 40px;
  262. margin-top: 10%;
  263. }
  264. .passwordContainer span{
  265. float: left;
  266. font-size: 18px;
  267. color: white;
  268. margin-left: 10px;
  269. }
  270. .password{
  271. width: 70%;
  272. height: 40px;
  273. border: 1px solid white;
  274. float: left;
  275. border-radius: 5px;
  276. }
  277. .noLogin{
  278. width: calc(70% + 84px);
  279. height: 40px;
  280. text-align: right;
  281. color: white;
  282. /* margin-left:15% ; */
  283. /* margin-right: 10px; */
  284. line-height: 40px;
  285. }
  286. .noLogin a:link{
  287. color: white;
  288. }
  289. .noLogin a:hover{
  290. color: white;
  291. }
  292. .noLogin a:visited{
  293. color: white;
  294. }
  295. .noLogin a:active{
  296. color: white;
  297. }
  298. .cu-btn{
  299. width: 80%;
  300. height: 50px;
  301. margin-left: 10%;
  302. /* margin-top: 10%; */
  303. }
  304. </style>