index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <template>
  2. <view class="page-container uni-column">
  3. <view class="uni-row" style="align-items: center;margin:8rpx 0 16rpx 0">
  4. <image class="logo" src="../../static/images/logo.png" @click="handleShowGear" />
  5. <uni-icons v-if="showGear > 4" class="icon-gear" type="gear-filled" size="60" style="z-index: 5;"
  6. @click="toggle('top')"></uni-icons>
  7. <view style="position: absolute; right: 12px;top: -4px;"><text>版本号:{{versionName}}</text></view>
  8. </view>
  9. <view class="title uni-row" v-if="loggedUsers.length > 0">
  10. <text>点击头像切换用户</text>
  11. </view>
  12. <!-- 输入框示例 -->
  13. <uni-popup ref="inputDialog" type="dialog" style="z-index: 2;">
  14. <uni-popup-dialog ref="inputClose" mode="input" title="手动设置" placeholder="请输入管理员密码"
  15. @confirm="dialogInputConfirm"></uni-popup-dialog>
  16. </uni-popup>
  17. <!-- 弹出层 -->
  18. <uni-popup ref="popup" background-color="#fff" style="z-index: 1;">
  19. <view style="height: auto;">
  20. <view v-if="showWrite" style="margin: 20rpx auto 10rpx;width: 90%;">
  21. <view>手动设置: &nbsp;服务器、检查、下载、炉号</view>
  22. <view class="baseUrl uni-row">
  23. <input v-model="baseUrl" placeholder="服务器地址" />
  24. <button @click="handleSetting" style="background-color: #1684fc;color: white;">设置</button>
  25. </view>
  26. <view class="baseUrl uni-row">
  27. <input v-model="path.checkAppURL" placeholder="检查更新" style="width: 100%;" />
  28. <!-- <button @click="handleSetting2" style="background-color: #1684fc;color: white;">确定</button> -->
  29. </view>
  30. <view class="baseUrl uni-row">
  31. <input v-model="path.updateAppURL" placeholder="app更新" style="width: 100%;" />
  32. <!-- <button @click="handleSetting2" style="background-color: #1684fc;color: white;">确定</button> -->
  33. </view>
  34. <view class="baseUrl uni-row">
  35. <input v-model="path.furnaceNoURL" placeholder="获取炉号信息地址" style="width: 100%;" />
  36. <!-- <button @click="handleSetting3" style="background-color: #1684fc;color: white;">确定</button> -->
  37. </view>
  38. </view>
  39. <view class="uni-row" style="justify-content: space-between;align-items: center;width: 90%;margin: 10rpx auto 20rpx;
  40. box-sizing: border-box;">
  41. <view style="margin-right: 32rpx;">设置网络地址:</view>
  42. <view class="uni-row" style="align-items: center;">
  43. <view style="margin-right: 24rpx;">内网</view>
  44. <switch :checked="baseUrl == path.publicURL" @change="switchChange" />
  45. <view style="margin-left: 24rpx;">外网</view>
  46. </view>
  47. <view style="width: 64rpx;height: 64rpx;background-color: white;border-radius: 50%;"
  48. @click="handleShowInputDialog('center')"></view>
  49. </view>
  50. </view>
  51. </uni-popup>
  52. <view class="add-user-btn uni-row" @click="handleShowLoginDialog(null)">
  53. <view class="icon uni-row">
  54. <text class="label">+</text>
  55. </view>
  56. <view class="btn-label">
  57. <text class="label">添加新账号</text>
  58. </view>
  59. </view>
  60. <view v-for="(item, index) in loggedUsers" class="item-user uni-row" @click="handleSelectUser(item)"
  61. @longpress="handleLongPressUser(item)">
  62. <view class="user-avatar uni-row"><text
  63. class="label">{{ item.nickName ? item.nickName.charAt(0) : null }}</text></view>
  64. <view class="user-info">
  65. <view class="nickname">
  66. <text class="label">{{item.nickName}}</text>
  67. </view>
  68. <view class="username">
  69. <text class="label">{{item.userName}}</text>
  70. </view>
  71. </view>
  72. </view>
  73. <dialog-login ref="loginDialog" />
  74. </view>
  75. </template>
  76. <script setup>
  77. import {
  78. onMounted,
  79. ref
  80. } from 'vue'
  81. import {
  82. onLoad,
  83. onReady
  84. } from '@dcloudio/uni-app'
  85. import {
  86. getUserInfo,
  87. getNickNameByUserName
  88. } from '@/api/login/index.js'
  89. import path from '@/api/base/path.js'
  90. import {
  91. getAppInfoListByType
  92. } from '@/api/business/app.js'
  93. import {
  94. getToken
  95. } from '@/utils/auth'
  96. import upgrade from '@/uni_modules/lgen-upgrade/js_sdk/upgrade.js'
  97. // 登录过的用户
  98. const loggedUsers = ref([])
  99. const loginDialog = ref(null)
  100. const userInfo = ref({})
  101. const users = ref([])
  102. const nickName = ref('')
  103. const useInnerUrl = ref(true)
  104. const baseUrl = ref(null)
  105. const showGear = ref(0)
  106. const appInfo = ref({})
  107. const newAppInfo = ref({})
  108. const updateFlag = ref(true) // 是否更新标志,如果为false,不能登录
  109. const popup = ref(null)
  110. const showWrite = ref(0)
  111. const inputDialog = ref(null)
  112. const showInputDialog = ref(0)
  113. const versionName = ref(null)
  114. onLoad(() => {
  115. //uni.clearStorageSync();
  116. initBaseUrl();
  117. getCurrentVersion()
  118. //getUser();
  119. !useInnerUrl.value && setTimeout(doCheckUpdata, 500)
  120. initPdfUrl();
  121. })
  122. onReady(() => {
  123. })
  124. function getCurrentVersion() {
  125. uni.getSystemInfo({
  126. success: function(res) {
  127. versionName.value = res.appVersion;
  128. }
  129. });
  130. console.log(versionName.value)
  131. }
  132. function doCheckUpdata() {
  133. checkUpdate().then(res => {
  134. updateFlag.value = res;
  135. console.log(updateFlag.value)
  136. if (!res) {
  137. uni.showModal({
  138. title: '更新',
  139. content: '发现新版本',
  140. showCancel: false,
  141. success: function(res) {
  142. if (res.confirm) {
  143. update();
  144. }
  145. }
  146. })
  147. }
  148. })
  149. }
  150. function initPdfUrl() {
  151. if (uni.getStorageSync('baseUrl')) {
  152. const urlList = JSON.parse(uni.getStorageSync('baseUrl'))
  153. // console.log(urlList)
  154. if (urlList.pdfAppURL == null) {
  155. // uni.showToast({
  156. // title: "更新url"
  157. // })
  158. urlList.pdfAppURL = path.pdfAppURL
  159. uni.setStorageSync('baseUrl', JSON.stringify(urlList));
  160. }
  161. }
  162. }
  163. function checkUpdate() {
  164. console.log("88888")
  165. uni.getSystemInfo({
  166. success: function(res) {
  167. appInfo.value = res;
  168. }
  169. });
  170. // false 版本号不一致,更新,true不需要更新
  171. let flag = getAppInfoListByType(path.checkAppURL, {
  172. type: appInfo.value.osName
  173. }).then(res => {
  174. console.log(res)
  175. newAppInfo.value = res.rows[0];
  176. console.log(newAppInfo.value, "111")
  177. if (res.rows[0]) {
  178. return appInfo.value.appWgtVersion === newAppInfo.value.versionName;
  179. } else {
  180. return true;
  181. }
  182. })
  183. console.log("flag", flag)
  184. return flag;
  185. }
  186. function update() {
  187. upgrade.downloadInstallApp(path.updateAppURL + newAppInfo.value.url);
  188. }
  189. function init() {
  190. uni.getStorageInfo({
  191. success: function(res) {
  192. for (let i = 0; i < res.keys.length; i++) {
  193. let storagekey = res.keys[i];
  194. uni.getStorage({
  195. key: storagekey,
  196. success: function(res) {
  197. if (storagekey !== 'token' && storagekey !== '__DC_STAT_UUID' &&
  198. storagekey !== 'baseUrl') {
  199. getNickNameByUserName(storagekey).then((response) => {
  200. if (response.code == 200) {
  201. loggedUsers.value.push({
  202. userName: storagekey,
  203. password: res.data,
  204. nickName: response.msg
  205. })
  206. }
  207. })
  208. }
  209. if (storagekey == 'baseUrl') {
  210. baseUrl.value = JSON.parse(res.data).baseUrl;
  211. path.checkAppURL = JSON.parse(res.data).checkAppURL;
  212. path.updateAppURL = JSON.parse(res.data).updateAppURL;
  213. path.furnaceNoURL = JSON.parse(res.data).furnaceNoURL;
  214. path.pdfAppURL = JSON.parse(res.data).pdfAppURL;
  215. }
  216. }
  217. });
  218. }
  219. }
  220. });
  221. }
  222. function initBaseUrl() {
  223. let urlList = {
  224. baseUrl: useInnerUrl ? path.innerURL : path.baseURL,
  225. checkAppURL: useInnerUrl ? '' : path.checkAppURL,
  226. updateAppURL: useInnerUrl ? path.innerUpdateAppURL : path.updateAppURL,
  227. furnaceNoURL: useInnerUrl ? path.innerFurnaceNoURL : path.furnaceNoURL,
  228. pdfAppURL: useInnerUrl ? path.innerPdfAppURL : path.pdfAppURL
  229. }
  230. uni.getStorage({
  231. key: 'baseUrl',
  232. fail: function() {
  233. uni.setStorageSync('baseUrl', JSON.stringify(urlList));
  234. },
  235. complete: function() {
  236. init();
  237. }
  238. });
  239. }
  240. function handleShowGear() {
  241. showGear.value += 1;
  242. }
  243. function handleShowWrite() {
  244. showWrite.value += 1;
  245. }
  246. function handleShowInputDialog(type) {
  247. showInputDialog.value += 1;
  248. if (showInputDialog.value > 4) {
  249. inputDialog.value.open(type);
  250. }
  251. }
  252. function dialogInputConfirm(val) {
  253. if (val == 'admin888') {
  254. showWrite.value = true;
  255. } else {
  256. uni.showToast({
  257. icon: 'none',
  258. title: '密码错误'
  259. })
  260. }
  261. }
  262. function toggle(type) {
  263. showGear.value += 1;
  264. if (showGear.value > 5) {
  265. showGear.value = 0;
  266. }
  267. showWrite.value = false;
  268. showInputDialog.value = 0;
  269. popup.value.open(type);
  270. }
  271. function switchChange(e) {
  272. if (e.detail.value) {
  273. baseUrl.value = path.publicURL;
  274. path.checkAppURL = path.publicURL;
  275. path.updateAppURL = path.outUpdateAppURL;
  276. path.furnaceNoURL = path.outFurnaceNoURL;
  277. path.pdfAppURL = path.outPdfAppURL
  278. handleSetting();
  279. } else {
  280. baseUrl.value = path.innerURL;
  281. path.checkAppURL = path.innerURL;
  282. path.updateAppURL = path.innerUpdateAppURL;
  283. path.furnaceNoURL = path.innerFurnaceNoURL;
  284. path.pdfAppURL = path.innerPdfAppURL
  285. handleSetting();
  286. }
  287. }
  288. function handleSetting() {
  289. let urlList = {
  290. baseUrl: baseUrl.value,
  291. checkAppURL: path.checkAppURL,
  292. updateAppURL: path.updateAppURL,
  293. furnaceNoURL: path.furnaceNoURL,
  294. pdfAppURL: path.pdfAppURL,
  295. }
  296. uni.setStorage({
  297. key: 'baseUrl',
  298. data: JSON.stringify(urlList),
  299. success: function() {
  300. uni.showToast({
  301. icon: "success",
  302. title: "设置成功"
  303. });
  304. doCheckUpdata();
  305. }
  306. });
  307. }
  308. const handleShowLoginDialog = (user) => {
  309. // 判断更新否,没更新不能登录
  310. if (!updateFlag.value) {
  311. uni.showToast({
  312. icon: 'none',
  313. title: '请更新后再登录'
  314. })
  315. setTimeout(doCheckUpdata, 500);
  316. } else {
  317. let _user = user ?? {}
  318. // 调用子组件中的方法
  319. loginDialog.value.open(_user)
  320. }
  321. }
  322. const handleSelectUser = (user) => {
  323. handleShowLoginDialog(user)
  324. }
  325. const handleLongPressUser = (user) => {
  326. uni.showModal({
  327. title: '提示', // 标题
  328. content: '是否删除此账号', // 提示内容
  329. cancelText: "取消", // 取消按钮的文字
  330. confirmText: "确认", // 确认按钮的文字
  331. //点击确定之后执行的代码
  332. success(res) {
  333. if (res.confirm) {
  334. uni.removeStorage({
  335. key: user.userName, // 键名
  336. success: () => {
  337. uni.showToast({
  338. title: '删除成功',
  339. icon: 'success',
  340. duration: 3000,
  341. });
  342. loggedUsers.value = [];
  343. init();
  344. }, // 成功回调函数
  345. fail: () => {}, // 失败回调函数
  346. })
  347. }
  348. }
  349. });
  350. }
  351. const handleAddUser = () => {
  352. uni.setStorage({
  353. key: 'logged-users',
  354. data: {
  355. users: ''
  356. },
  357. success: () => {}
  358. })
  359. }
  360. </script>
  361. <style lang="scss">
  362. .page-container {
  363. overflow: auto;
  364. }
  365. .logo {
  366. width: 120rpx;
  367. height: 120rpx;
  368. margin: 0 auto;
  369. }
  370. .title {
  371. height: 80rpx;
  372. justify-content: center;
  373. align-items: center;
  374. color: #999999;
  375. }
  376. .icon-gear {
  377. position: fixed;
  378. right: 40rpx;
  379. font-size: 60rpx;
  380. }
  381. .baseUrl {
  382. border: 2rpx solid gray;
  383. width: 100%;
  384. margin: 20rpx auto;
  385. border-radius: 12rpx;
  386. align-items: center;
  387. input {
  388. width: 70%;
  389. padding: 16rpx 24rpx;
  390. }
  391. button {
  392. width: 30%;
  393. }
  394. }
  395. .item-user {
  396. margin: 32rpx;
  397. margin-top: 0;
  398. padding: 32rpx;
  399. background-color: #FFFFFF;
  400. align-items: center;
  401. .user-avatar {
  402. width: 128rpx;
  403. height: 128rpx;
  404. border-radius: 64rpx;
  405. background-color: #F1F2F3;
  406. justify-content: center;
  407. align-items: center;
  408. .label {
  409. font-size: 64rpx;
  410. }
  411. }
  412. .user-info {
  413. flex: 1;
  414. height: 96rpx;
  415. padding-left: 32rpx;
  416. .nickname {
  417. .label {
  418. font-weight: bold;
  419. font-size: 40rpx;
  420. }
  421. }
  422. .username {
  423. margin-top: 8rpx;
  424. .label {
  425. font-size: 32rpx;
  426. }
  427. }
  428. }
  429. }
  430. .add-user-btn {
  431. margin: 32rpx;
  432. padding: 32rpx;
  433. background-color: #FFFFFF;
  434. align-items: center;
  435. .icon {
  436. width: 128rpx;
  437. height: 128rpx;
  438. align-items: center;
  439. justify-content: center;
  440. background-color: #F1F2F3;
  441. border-radius: 64rpx;
  442. .label {
  443. color: #FFFFFF;
  444. font-size: 128rpx;
  445. }
  446. }
  447. .btn-label {
  448. flex: 1;
  449. padding-left: 32rpx;
  450. .label {
  451. font-size: 40rpx;
  452. }
  453. }
  454. }
  455. </style>