login.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <view style="height: 100vh;">
  3. <view class="status_bar"></view>
  4. <view class="logo" @longpress="logoTime">
  5. <image src="../../static/image/login/8eef2e54055a5b072a5dc000919a7ae.png" mode=""></image>
  6. </view>
  7. <view class="set" @click="set" v-if="setTF">
  8. <u-icon name="setting-fill" size="40" color="#72CD9C"></u-icon>
  9. </view>
  10. <form @submit="formSubmit">
  11. <view class="uni-form-item uni-column">
  12. <view class="username">
  13. <u-icon name="account" size="36" style="margin-right:30rpx;color: #72CD9C;"></u-icon>
  14. <u-input class="uni-input" name="username" v-model="formdata.username" placeholder-class="icon iconfont icon-bianji1"
  15. placeholder="请输入用户名" @blur="blur" />
  16. </view>
  17. <view class="passwold">
  18. <u-icon name="lock" size="36" style="margin-right:30rpx;color: #72CD9C;"></u-icon>
  19. <u-input v-model="formdata.passwold" type="password" :password-icon="true" :clearable="false" placeholder="请输入密码"
  20. @confirm="formSubmit" @input="passwoldddata" />
  21. </view>
  22. <view class="aboutpass">
  23. <u-checkbox-group>
  24. <u-checkbox v-model="checked" :label-disabled="false" size="22" @change="rempass">记住密码</u-checkbox>
  25. </u-checkbox-group>
  26. </view>
  27. <view class="uni-btn-v">
  28. <button form-type="submit">登 录</button>
  29. </view>
  30. </view>
  31. </form>
  32. <view class="bg">
  33. <image src="../../static/image/login/850c9307f4ef2d7dc6db1049711ab55.jpg" mode=""></image>
  34. </view>
  35. <view class="setbg" v-if="setbgtf">
  36. <view class="mengban" @click.stop="setbgtf = !setbgtf"></view>
  37. <view class="set_http">
  38. <view class="set_http_top">
  39. <u-icon name="close" size="40" @click="setbgtf = !setbgtf"></u-icon>
  40. <p>设置服务器地址</p>
  41. <u-icon name="checkbox-mark" size="40" @click="sethttp"></u-icon>
  42. </view>
  43. <view class="set_http_bot">
  44. <p>服务器访问地址</p>
  45. <view class="set_http_bot_input">
  46. <input type="text" v-model="value" placeholder="请在此处输入服务器地址(http://...)" />
  47. <u-icon :name="arrowtf?'arrow-up':'arrow-down'" @click="arrow"></u-icon>
  48. </view>
  49. <scroll-view scroll-y="true" class="scroll-Y" v-if="arrowtf">
  50. <view :id="'demo'+index" class="scroll-view-item uni-bg-red" v-for="item,index in httparr" :key="index" @click="value = item">{{item}}</view>
  51. </scroll-view>
  52. </view>
  53. </view>
  54. </view>
  55. <u-modal title="升级中请勿随意操作" :show-confirm-button="false" v-model="showA" :content="contentA">
  56. <view class="upgradeBox">
  57. <u-line-progress v-show="isShow" active-color="#19be6b" :striped="true" :percent="percentNum" :striped-active="true"></u-line-progress>
  58. </view>
  59. </u-modal>
  60. </view>
  61. </template>
  62. <script>
  63. export default {
  64. data() {
  65. return {
  66. checked: false,
  67. formdata: {
  68. username: '',
  69. passwold: ''
  70. },
  71. setbgtf: false,
  72. setTF: false,
  73. value: "http://8.136.98.49:8002",
  74. httparr: ["http://8.136.98.49:8002", "http://182.92.193.64:8002"],
  75. arrowtf: false,
  76. showA: false, //
  77. contentA: '',
  78. isShow: false, //进度条
  79. percentNum: 0, //在线下载进度
  80. }
  81. },
  82. onLoad() {
  83. uni.getStorage({
  84. key: 'user_pass',
  85. success: (res) => {
  86. if (res.data) {
  87. this.formdata.passwold = res.data
  88. this.checked = true
  89. } else {
  90. this.checked = false
  91. }
  92. }
  93. })
  94. uni.getStorage({
  95. key: 'user_name',
  96. success: (res) => {
  97. this.formdata.username = res.data
  98. }
  99. })
  100. uni.getStorage({
  101. key: 'http',
  102. success: (res) => {
  103. this.value = res.data
  104. }
  105. })
  106. },
  107. onShow() {
  108. this.getEquipList()
  109. },
  110. methods: {
  111. async getEquipList() {
  112. const res = await this.$myRequest({
  113. url: '/api/api_gateway?method=home.homes.app_version_record',
  114. data: {
  115. ret: "first"
  116. }
  117. })
  118. console.log(res)
  119. this.appName = res[0].app_name
  120. this.versions = Number(res[0].app_num.match(/\d+/g).join(""))
  121. var id = Number(plus.runtime.version.match(/\d+/g).join(""))
  122. console.log(this.versions,id)
  123. if (this.versions > id) {
  124. uni.showModal({
  125. title: '提示',
  126. content: '检测到有新版本,是否更新?',
  127. success: (res) => {
  128. if (res.confirm) {
  129. console.log('用户点击确定');
  130. this.showA = true
  131. this.isShow = true
  132. this.upgrade()
  133. } else if (res.cancel) {
  134. plus.runtime.quit();
  135. console.log('用户点击取消');
  136. }
  137. }
  138. })
  139. } else {
  140. uni.getStorage({
  141. key: 'session_key',
  142. success: (res) => {
  143. console.log(res)
  144. if (res.data != "") {
  145. uni.switchTab({
  146. url: "../index/index"
  147. })
  148. }
  149. },
  150. })
  151. }
  152. },
  153. upgrade() {
  154. console.log(this.appName)
  155. var url = this.value + "/app_file/" + this.appName
  156. console.log(url)
  157. const downloadTask = uni.downloadFile({
  158. url: url, //仅为示例,并非真实的资源
  159. success: (res) => {
  160. console.log(res)
  161. if (res.statusCode === 200) {
  162. console.log('下载成功');
  163. console.log('安装包下载成功,即将安装:' + JSON.stringify(res, null, 4));
  164. plus.runtime.openFile(res.tempFilePath);
  165. }
  166. },
  167. fail: (err) => {
  168. console.log(err)
  169. },
  170. complete: (com) => {
  171. console.log(com)
  172. }
  173. });
  174. downloadTask.onProgressUpdate((res) => {
  175. this.percentNum = res.progress
  176. if (res.progress == 100) {
  177. console.log('下载完成了')
  178. }
  179. });
  180. },
  181. async formSubmit() {
  182. const res = await this.$myRequest({
  183. url: '/api/api_gateway?method=user.login.login_user',
  184. data: {
  185. username: this.formdata.username,
  186. password: this.formdata.passwold
  187. }
  188. })
  189. console.log(res.session_key)
  190. let session_key = res.session_key
  191. uni.setStorage({
  192. key: 'session_key',
  193. data: session_key,
  194. success: () => {
  195. uni.switchTab({
  196. url: "../index/index"
  197. })
  198. }
  199. })
  200. },
  201. passwoldddata() {
  202. this.formdata.passwold = this.formdata.passwold.replace(/[\u4E00-\u9FA5]/g, '')
  203. },
  204. rempass(val) {
  205. if (val.value) {
  206. uni.setStorage({
  207. key: 'user_pass',
  208. data: this.formdata.passwold,
  209. success: function() {
  210. console.log('success');
  211. }
  212. })
  213. } else {
  214. uni.removeStorage({
  215. key: 'user_pass',
  216. success: function() {
  217. console.log('success');
  218. }
  219. })
  220. }
  221. },
  222. blur(val) {
  223. uni.setStorage({
  224. key: 'user_name',
  225. data: val,
  226. success: function() {
  227. console.log('success');
  228. }
  229. })
  230. },
  231. logoTime() {
  232. this.setTF = true
  233. },
  234. set() {
  235. this.setbgtf = true
  236. },
  237. sethttp() {
  238. uni.setStorage({
  239. key: 'http',
  240. data: this.value,
  241. success: () => {
  242. // console.log(this.value);
  243. this.setbgtf = false
  244. uni.showToast({
  245. title: "修改成功",
  246. icon: "none"
  247. })
  248. this.getEquipList()
  249. }
  250. });
  251. },
  252. arrow() {
  253. this.arrowtf = !this.arrowtf
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss">
  259. .logo {
  260. width: 100%;
  261. height: 340rpx;
  262. text-align: center;
  263. display: flex;
  264. align-items: center;
  265. padding-top: 240rpx;
  266. image {
  267. width: 280rpx;
  268. margin: 0 auto;
  269. height: 120rpx;
  270. }
  271. }
  272. .set {
  273. position: absolute;
  274. right: 50rpx;
  275. top: 100rpx;
  276. }
  277. .bg {
  278. width: 100%;
  279. position: fixed;
  280. bottom: 0;
  281. z-index: -1;
  282. image {
  283. width: 100%;
  284. }
  285. }
  286. /deep/.u-input__right-icon {
  287. line-height: 35px !important;
  288. }
  289. .uni-form-item {
  290. width: 100%;
  291. .username {
  292. width: 80%;
  293. margin: 0 auto;
  294. display: flex;
  295. margin-bottom: 40rpx;
  296. padding-bottom: 10rpx;
  297. border-bottom: 2rpx solid #C3C3C3;
  298. }
  299. .passwold {
  300. width: 80%;
  301. margin: 0 auto;
  302. display: flex;
  303. margin-bottom: 40rpx;
  304. padding-bottom: 10rpx;
  305. border-bottom: 2rpx solid #C3C3C3;
  306. }
  307. .aboutpass {
  308. width: 80%;
  309. margin: 0 auto;
  310. display: flex;
  311. justify-content: flex-end;
  312. p {
  313. color: #C0C0C0;
  314. font-size: 28rpx;
  315. }
  316. /deep/.u-checkbox__label {
  317. font-size: 28rpx;
  318. color: #C0C0C0;
  319. margin-right: 0;
  320. }
  321. }
  322. .uni-btn-v {
  323. width: 80%;
  324. margin: 112rpx auto 0;
  325. position: relative;
  326. z-index: 100;
  327. button {
  328. width: 100%;
  329. height: 72rpx;
  330. line-height: 75rpx;
  331. background-color: #5DC18B;
  332. color: #FFFFFF;
  333. border-radius: 36rpx;
  334. font-size: 28rpx;
  335. }
  336. }
  337. }
  338. .setbg {
  339. width: 100%;
  340. height: 100vh;
  341. position: absolute;
  342. top: 0;
  343. z-index: 99999;
  344. .mengban {
  345. width: 100%;
  346. height: 100vh;
  347. position: absolute;
  348. top: 0;
  349. background-color: rgba($color: #000000, $alpha: 0.5);
  350. }
  351. .set_http {
  352. position: absolute;
  353. width: 90%;
  354. left: 5%;
  355. top: 30%;
  356. .set_http_top {
  357. display: flex;
  358. justify-content: space-around;
  359. background-color: #5DC18B;
  360. height: 60px;
  361. line-height: 60px;
  362. color: #FFFFFF;
  363. border-top-right-radius: 20px;
  364. border-top-left-radius: 20px;
  365. font-size: 32rpx;
  366. }
  367. .set_http_bot {
  368. height: 150px;
  369. background-color: #FFFFFF;
  370. border-bottom-right-radius: 20px;
  371. border-bottom-left-radius: 20px;
  372. padding: 30px;
  373. .set_http_bot_input {
  374. margin-top: 20rpx;
  375. border: 2rpx solid #bdb6a6;
  376. border-radius: 20rpx;
  377. padding: 10rpx 40rpx 0 20rpx;
  378. font-size: 32rpx;
  379. height: 30px;
  380. display: flex;
  381. justify-content: space-between;
  382. input {
  383. width: 90%;
  384. }
  385. }
  386. }
  387. .scroll-Y {
  388. border: 2rpx solid #d0d0d0;
  389. border-radius: 20rpx;
  390. .scroll-view-item {
  391. padding-left: 20rpx;
  392. height: 70rpx;
  393. font-size: 28rpx;
  394. line-height: 70rpx;
  395. border-bottom: 2rpx solid #d0d0d0;
  396. }
  397. }
  398. }
  399. }
  400. .upgradeBox {
  401. padding: 15rpx;
  402. }
  403. </style>