index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <view class="container">
  3. <view class="title-content">
  4. <text class="title">哈密市重点项目<br>建设及工作可视<br>化管理平台</text>
  5. </view>
  6. <view class="login-form-content">
  7. <view class="welcome-text">请登录您现有的账户</view>
  8. <view class="item-text">账号</view>
  9. <view class="input-item flex align-center">
  10. <input v-model="loginForm.userName" class="input" type="text" placeholder="请输入您现有的账号" maxlength="30" />
  11. </view>
  12. <view class="item-text">密码</view>
  13. <view class="input-item flex align-center">
  14. <input v-model="loginForm.password" @keyup.enter="handleLogin" :type="passType" class="input"
  15. placeholder="请输入您的密码" maxlength="20" />
  16. <view class="pass-item-icon" :class="passType === 'text' ? 'pass-item-hide' :''">
  17. <image :src="passIcon" @click="changeInputType()"></image>
  18. </view>
  19. </view>
  20. <view class="forget-pass-item">
  21. <text class="forget-pass" @click="goToForgetPass()">忘记密码</text>
  22. </view>
  23. <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
  24. <view class="change-ip">
  25. <text class="forget-pass" @click="goToChangeIP()">更换服务地址</text>
  26. </view>
  27. </view>
  28. <u-overlay :show="isDownload">
  29. <view class="download-box">
  30. <view class="loading-box">
  31. <view class="loading-icon">
  32. <u-loading-icon v-if="downloadPrecent !== '100'" size="40"></u-loading-icon>
  33. <u-icon v-else name="checkmark" size="40"></u-icon>
  34. </view>
  35. <view class="loading-text">{{downloadText}}</view>
  36. <view class="loading-progress">
  37. <u-line-progress :percentage="downloadPrecent" activeColor="#1869F6"></u-line-progress>
  38. </view>
  39. </view>
  40. </view>
  41. </u-overlay>
  42. </view>
  43. </template>
  44. <script setup>
  45. import {
  46. ref
  47. } from "vue";
  48. import {
  49. onLoad,
  50. onShow
  51. } from "@dcloudio/uni-app"
  52. import {
  53. getNewestVersion
  54. } from '@/api/login.js'
  55. import {
  56. validateVersion
  57. } from "@/utils/validateVersion.js"
  58. import user from '@/store/modules/user'
  59. import config from '@/config.js'
  60. import store from '@/store'
  61. import passSee from "@/static/pass-see.svg"
  62. import passHide from "@/static/pass-hide.svg"
  63. // 登录信息
  64. const loginForm = ref({
  65. userName: "",
  66. password: ""
  67. });
  68. let passType = ref("password")
  69. let passIcon = ref(passHide)
  70. function changeInputType() {
  71. passType.value = passType.value === "password" ? "text" : "password"
  72. passIcon.value = passType.value === "password" ? passHide : passSee
  73. }
  74. // 登录
  75. async function handleLogin() {
  76. if (functionBan) {
  77. return uni.showToast({
  78. title: '请更新至最新版本后操作。',
  79. icon: 'none',
  80. mask: false,
  81. duration: 1000
  82. });
  83. }
  84. if (loginForm.value.userName === "") {
  85. uni.showToast({
  86. title: '请输入您的账号',
  87. icon: 'error',
  88. mask: false,
  89. duration: 1000
  90. });
  91. } else if (loginForm.value.password === "") {
  92. uni.showToast({
  93. title: '请输入您的密码',
  94. icon: 'error',
  95. mask: false,
  96. duration: 1000
  97. });
  98. } else {
  99. uni.getNetworkType({
  100. success: function(res) {
  101. if (res.networkType === "none") {
  102. // console.log('injudge');
  103. // uni.showToast({
  104. // title: '请输入您的账号',
  105. // icon: 'error',
  106. // mask: false,
  107. // duration: 1000
  108. // });
  109. // console.log('beforeJudge');
  110. // return
  111. const serverAddress = uni.getStorageSync('serverAddress')
  112. const baseUrlIp = serverAddress ? serverAddress : config.baseUrl
  113. let titleText = `服务器ip:${baseUrlIp} 连接不上,请检查网络`
  114. uni.showModal({
  115. // title: '网络不通,请检查网络情况',
  116. title: '提示',
  117. content: titleText,
  118. icon: 'none',
  119. mask: false,
  120. duration: 3000,
  121. showCancel: false,
  122. success: function(res) {
  123. if (res.confirm) {
  124. console.log('用户点击确定');
  125. } else if (res.cancel) {
  126. console.log('用户点击取消');
  127. }
  128. }
  129. });
  130. } else {
  131. uni.showToast({
  132. title: '登录中,请耐心等待...',
  133. icon: 'loading',
  134. mask: false,
  135. duration: 1000
  136. });
  137. store.dispatch('Login', loginForm.value).then(() => {
  138. loginSuccess()
  139. }).catch(err => {
  140. console.log(err);
  141. })
  142. }
  143. },
  144. fail: function(err) {
  145. return uni.showToast({
  146. title: '获取手机网络状态失败。',
  147. icon: 'error',
  148. mask: false,
  149. duration: 1000
  150. });
  151. }
  152. })
  153. }
  154. };
  155. // 设置用户信息
  156. function loginSuccess(result) {
  157. store.dispatch('GetInfo').then(res => {
  158. uni.switchTab({
  159. url: '/pages/index'
  160. });
  161. })
  162. }
  163. // 忘记密码
  164. function goToForgetPass() {
  165. if (functionBan) {
  166. return uni.showToast({
  167. title: '请更新至最新版本后操作。',
  168. icon: 'none',
  169. mask: false,
  170. duration: 1000
  171. });
  172. }
  173. uni.navigateTo({
  174. url: '/pages/login/forgetPass/index'
  175. })
  176. }
  177. // 更换服务地址
  178. function goToChangeIP() {
  179. if (functionBan) {
  180. return uni.showToast({
  181. title: '请更新至最新版本后操作。',
  182. icon: 'none',
  183. mask: false,
  184. duration: 1000
  185. });
  186. }
  187. uni.navigateTo({
  188. url: '/pages/login/changeIP/index'
  189. })
  190. }
  191. // 禁止功能使用
  192. let functionBan = false
  193. // 是否正在下载新版本
  194. let isDownload = ref(false)
  195. // 下载进度
  196. let downloadPrecent = ref(0)
  197. // 下载文件
  198. let downloadFilePath = null;
  199. // 下载提示文字
  200. let downloadText = ref("下载中,请勿关闭软件。")
  201. // 判断是否最新版本
  202. function judgeIsNewest() {
  203. //#ifdef APP-PLUS
  204. // 获取系统信息
  205. uni.getSystemInfo({
  206. // 成功则进行对比
  207. success: async (res) => {
  208. // 获取最新版本
  209. const newsetVersionRes = await getNewestVersion().catch(() => {
  210. uni.showModal({
  211. title: '错误',
  212. content: '获取最新系统版本失败。'
  213. });
  214. });
  215. let newsetVersion = newsetVersionRes.data.version;
  216. let higherThanNewest = validateVersion(res.appWgtVersion, newsetVersion)
  217. // 如果版本低于服务上的最新版
  218. if (!higherThanNewest) {
  219. // 禁用功能
  220. functionBan = true;
  221. // 最新版本下载链接
  222. const serverAddress = uni.getStorageSync('serverAddress');
  223. const baseUrlIp = serverAddress ? serverAddress : config.baseUrl;
  224. const downloadUrl = baseUrlIp + '/projects/outApi/version/download';
  225. // 展示下载提示
  226. uni.showModal({
  227. title: '新版本提醒',
  228. content: `检测到新版本“${newsetVersion}”,请下载更新。`,
  229. confirmText: '去下载',
  230. cancelText: '退出软件',
  231. cancelColor: '#808080',
  232. success: async (modelRes) => {
  233. // 确认选择
  234. if (modelRes.confirm) {
  235. if (plus.os.name == "Android") {
  236. isDownload.value = true
  237. let downloadTask = uni.downloadFile({
  238. url: downloadUrl,
  239. success: (successRes => {
  240. downloadFilePath = successRes.tempFilePath;
  241. uni.hideLoading();
  242. plus.runtime.install(successRes.tempFilePath);
  243. isDownload.value = false;
  244. downloadPrecent.value = 0;
  245. }),
  246. fail: (failRes) => {
  247. uni.hideLoading();
  248. uni.showModal({
  249. title: '错误',
  250. content: '下载最新版本失败。'
  251. });
  252. isDownload.value = false;
  253. downloadPrecent.value = 0;
  254. }
  255. })
  256. downloadTask.onProgressUpdate(res => {
  257. downloadPrecent.value = res.progress
  258. if (res.progress == 100) {
  259. downloadText = "下载完成,即将安装最新版本"
  260. }
  261. })
  262. };
  263. } else {
  264. // 退出软件
  265. plus.runtime.quit();
  266. }
  267. },
  268. })
  269. }
  270. },
  271. // 失败禁用功能并弹窗
  272. fail: () => {
  273. functionBan = true;
  274. uni.showModal({
  275. title: '错误',
  276. content: '获取当前系统版本失败。'
  277. })
  278. }
  279. })
  280. //#endif
  281. }
  282. // 判断是否已经下载了最新版
  283. const judgeIsDownloadNewest = () => {
  284. if (downloadFilePath) {
  285. uni.showModal({
  286. title: '新版本已下载',
  287. content: '最新版本已下载完毕,请点击安装。',
  288. confirmText: '去安装',
  289. showCancel: false,
  290. success: async (modelRes) => {
  291. if (modelRes.confirm) {
  292. if (plus.os.name == "Android") {
  293. plus.runtime.install(downloadFilePath);
  294. }
  295. }
  296. }
  297. })
  298. }
  299. }
  300. onLoad(() => {
  301. judgeIsNewest()
  302. })
  303. onShow(() => {
  304. judgeIsDownloadNewest()
  305. })
  306. </script>
  307. <style lang="scss">
  308. page {
  309. height: 100%;
  310. background-color: #EAF0FA;
  311. }
  312. .container {
  313. position: relative;
  314. width: 100%;
  315. height: 100%;
  316. background: linear-gradient(108deg, #192DE8 0%, #1DA0FF 53%, #84D8FF 100%);
  317. .title-content {
  318. width: 100%;
  319. height: 46%;
  320. z-index: 1;
  321. background: url('@/static/login_bg.png');
  322. background-size: 100% 100%;
  323. .title {
  324. position: absolute;
  325. top: 10.5%;
  326. left: 7.4%;
  327. font-size: 52rpx;
  328. font-weight: 700;
  329. color: #FFFFFF;
  330. }
  331. }
  332. .login-form-content {
  333. position: absolute;
  334. top: 32%;
  335. left: 0;
  336. width: 100%;
  337. height: 68%;
  338. padding: 40rpx 7%;
  339. background-color: #fff;
  340. border-radius: 40rpx 40rpx 0rpx 0rpx;
  341. .welcome-text {
  342. margin: 0 0 60rpx;
  343. font-size: 44rpx;
  344. font-weight: 700;
  345. color: #C6C6CD;
  346. }
  347. .item-text {
  348. font-size: 36rpx;
  349. font-weight: 400;
  350. font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  351. color: #343437;
  352. }
  353. .input-item {
  354. height: 90rpx;
  355. margin: 20rpx auto 30rpx;
  356. font-size: 28rpx;
  357. background-color: #f5f6f7;
  358. border-radius: 16rpx;
  359. .input {
  360. width: 100%;
  361. font-size: 14px;
  362. line-height: 20px;
  363. text-align: left;
  364. padding-left: 15px;
  365. }
  366. }
  367. .pass-item-icon {
  368. flex: 1;
  369. height: 100%;
  370. line-height: 80rpx;
  371. text-align: right;
  372. padding-right: 15px;
  373. image {
  374. width: 36rpx;
  375. height: 18rpx;
  376. }
  377. }
  378. .pass-item-hide {
  379. image {
  380. width: 36rpx;
  381. height: 28rpx;
  382. }
  383. }
  384. .forget-pass-item {
  385. text-align: right;
  386. }
  387. .forget-pass {
  388. color: #1869F6;
  389. border-bottom: 2rpx solid #1869F6;
  390. }
  391. .login-btn {
  392. margin-top: 40rpx;
  393. height: 45px;
  394. background: #1869F6;
  395. border-radius: 16rpx;
  396. }
  397. }
  398. .change-ip {
  399. margin-top: 200rpx;
  400. text-align: center;
  401. .forget-pass {
  402. color: #1869F6;
  403. border-bottom: 2rpx solid #1869F6;
  404. }
  405. }
  406. .download-box {
  407. display: flex;
  408. align-items: center;
  409. justify-content: center;
  410. height: 100%;
  411. .loading-box {
  412. display: flex;
  413. flex-direction: column;
  414. justify-content: space-between;
  415. width: 360rpx;
  416. height: 360rpx;
  417. padding: 20rpx;
  418. background-color: #fff;
  419. border-radius: 40rpx;
  420. }
  421. .loading-icon {
  422. flex: 4;
  423. display: flex;
  424. flex-direction: column;
  425. justify-content: center;
  426. }
  427. .loading-text {
  428. flex: 1;
  429. display: flex;
  430. align-items: flex-end;
  431. text-align: center;
  432. }
  433. .loading-progress {
  434. flex: 1;
  435. display: flex;
  436. align-items: flex-end;
  437. }
  438. }
  439. }
  440. </style>