index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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 &&
  120. setTimeout(doCheckUpdata, 500)
  121. initPdfUrl();
  122. })
  123. onReady(() => {
  124. })
  125. function getCurrentVersion() {
  126. uni.getSystemInfo({
  127. success: function(res) {
  128. versionName.value = res.appVersion;
  129. }
  130. });
  131. console.log(versionName.value)
  132. }
  133. function doCheckUpdata() {
  134. checkUpdate().then(res => {
  135. updateFlag.value = res;
  136. console.log(updateFlag.value)
  137. if (!res) {
  138. uni.showModal({
  139. title: '更新',
  140. content: '发现新版本',
  141. showCancel: false,
  142. success: function(res) {
  143. if (res.confirm) {
  144. update();
  145. }
  146. }
  147. })
  148. }
  149. })
  150. }
  151. function initPdfUrl() {
  152. if (uni.getStorageSync('baseUrl')) {
  153. const urlList = JSON.parse(uni.getStorageSync('baseUrl'))
  154. // console.log(urlList)
  155. if (urlList.pdfAppURL == null) {
  156. // uni.showToast({
  157. // title: "更新url"
  158. // })
  159. urlList.pdfAppURL = path.pdfAppURL
  160. uni.setStorageSync('baseUrl', JSON.stringify(urlList));
  161. }
  162. }
  163. }
  164. function checkUpdate() {
  165. console.log("88888")
  166. uni.getSystemInfo({
  167. success: function(res) {
  168. appInfo.value = res;
  169. }
  170. });
  171. // false 版本号不一致,更新,true不需要更新
  172. let flag = getAppInfoListByType(path.checkAppURL, {
  173. type: appInfo.value.osName
  174. }).then(res => {
  175. console.log(res)
  176. newAppInfo.value = res.rows[0];
  177. console.log(newAppInfo.value, "111")
  178. if (res.rows[0]) {
  179. return appInfo.value.appWgtVersion === newAppInfo.value.versionName;
  180. } else {
  181. return true;
  182. }
  183. })
  184. console.log("flag", flag)
  185. return flag;
  186. }
  187. function update() {
  188. upgrade.downloadInstallApp(path.updateAppURL + newAppInfo.value.url);
  189. }
  190. function init() {
  191. uni.getStorageInfo({
  192. success: function(res) {
  193. for (let i = 0; i < res.keys.length; i++) {
  194. let storagekey = res.keys[i];
  195. uni.getStorage({
  196. key: storagekey,
  197. success: function(res) {
  198. if (storagekey !== 'token' && storagekey !== '__DC_STAT_UUID' &&
  199. storagekey !== 'baseUrl') {
  200. getNickNameByUserName(storagekey).then((response) => {
  201. if (response.code == 200) {
  202. loggedUsers.value.push({
  203. userName: storagekey,
  204. password: res.data,
  205. nickName: response.msg
  206. })
  207. }
  208. })
  209. }
  210. if (storagekey == 'baseUrl') {
  211. baseUrl.value = JSON.parse(res.data).baseUrl;
  212. path.checkAppURL = JSON.parse(res.data).checkAppURL;
  213. path.updateAppURL = JSON.parse(res.data).updateAppURL;
  214. path.furnaceNoURL = JSON.parse(res.data).furnaceNoURL;
  215. path.pdfAppURL = JSON.parse(res.data).pdfAppURL;
  216. }
  217. }
  218. });
  219. }
  220. }
  221. });
  222. }
  223. function initBaseUrl() {
  224. let urlList = {
  225. baseUrl: useInnerUrl ? path.innerURL : path.baseURL,
  226. checkAppURL: useInnerUrl ? '' : path.checkAppURL,
  227. updateAppURL: useInnerUrl ? path.innerUpdateAppURL : path.updateAppURL,
  228. furnaceNoURL: useInnerUrl ? path.innerFurnaceNoURL : path.furnaceNoURL,
  229. pdfAppURL: useInnerUrl ? path.innerPdfAppURL : path.pdfAppURL
  230. }
  231. uni.getStorage({
  232. key: 'baseUrl',
  233. fail: function() {
  234. uni.setStorageSync('baseUrl', JSON.stringify(urlList));
  235. },
  236. complete: function() {
  237. init();
  238. }
  239. });
  240. }
  241. function handleShowGear() {
  242. showGear.value += 1;
  243. }
  244. function handleShowWrite() {
  245. showWrite.value += 1;
  246. }
  247. function handleShowInputDialog(type) {
  248. showInputDialog.value += 1;
  249. if (showInputDialog.value > 4) {
  250. inputDialog.value.open(type);
  251. }
  252. }
  253. function dialogInputConfirm(val) {
  254. if (val == 'admin888') {
  255. showWrite.value = true;
  256. } else {
  257. uni.showToast({
  258. icon: 'none',
  259. title: '密码错误'
  260. })
  261. }
  262. }
  263. function toggle(type) {
  264. showGear.value += 1;
  265. if (showGear.value > 5) {
  266. showGear.value = 0;
  267. }
  268. showWrite.value = false;
  269. showInputDialog.value = 0;
  270. popup.value.open(type);
  271. }
  272. function switchChange(e) {
  273. if (e.detail.value) {
  274. baseUrl.value = path.publicURL;
  275. path.checkAppURL = path.publicURL;
  276. path.updateAppURL = path.outUpdateAppURL;
  277. path.furnaceNoURL = path.outFurnaceNoURL;
  278. path.pdfAppURL = path.outPdfAppURL
  279. handleSetting();
  280. } else {
  281. baseUrl.value = path.innerURL;
  282. path.checkAppURL = path.innerURL;
  283. path.updateAppURL = path.innerUpdateAppURL;
  284. path.furnaceNoURL = path.innerFurnaceNoURL;
  285. path.pdfAppURL = path.innerPdfAppURL
  286. handleSetting();
  287. }
  288. }
  289. function handleSetting() {
  290. let urlList = {
  291. baseUrl: baseUrl.value,
  292. checkAppURL: path.checkAppURL,
  293. updateAppURL: path.updateAppURL,
  294. furnaceNoURL: path.furnaceNoURL,
  295. pdfAppURL: path.pdfAppURL,
  296. }
  297. uni.setStorage({
  298. key: 'baseUrl',
  299. data: JSON.stringify(urlList),
  300. success: function() {
  301. uni.showToast({
  302. icon: "success",
  303. title: "设置成功"
  304. });
  305. doCheckUpdata();
  306. }
  307. });
  308. }
  309. const handleShowLoginDialog = (user) => {
  310. // 判断更新否,没更新不能登录
  311. if (!updateFlag.value) {
  312. uni.showToast({
  313. icon: 'none',
  314. title: '请更新后再登录'
  315. })
  316. setTimeout(doCheckUpdata, 500);
  317. } else {
  318. let _user = user ?? {}
  319. // 调用子组件中的方法
  320. loginDialog.value.open(_user)
  321. }
  322. }
  323. const handleSelectUser = (user) => {
  324. handleShowLoginDialog(user)
  325. }
  326. const handleLongPressUser = (user) => {
  327. uni.showModal({
  328. title: '提示', // 标题
  329. content: '是否删除此账号', // 提示内容
  330. cancelText: "取消", // 取消按钮的文字
  331. confirmText: "确认", // 确认按钮的文字
  332. //点击确定之后执行的代码
  333. success(res) {
  334. if (res.confirm) {
  335. uni.removeStorage({
  336. key: user.userName, // 键名
  337. success: () => {
  338. uni.showToast({
  339. title: '删除成功',
  340. icon: 'success',
  341. duration: 3000,
  342. });
  343. loggedUsers.value = [];
  344. init();
  345. }, // 成功回调函数
  346. fail: () => {}, // 失败回调函数
  347. })
  348. }
  349. }
  350. });
  351. }
  352. const handleAddUser = () => {
  353. uni.setStorage({
  354. key: 'logged-users',
  355. data: {
  356. users: ''
  357. },
  358. success: () => {}
  359. })
  360. }
  361. </script>
  362. <style lang="scss">
  363. .page-container {
  364. overflow: auto;
  365. }
  366. .logo {
  367. width: 120rpx;
  368. height: 120rpx;
  369. margin: 0 auto;
  370. }
  371. .title {
  372. height: 80rpx;
  373. justify-content: center;
  374. align-items: center;
  375. color: #999999;
  376. }
  377. .icon-gear {
  378. position: fixed;
  379. right: 40rpx;
  380. font-size: 60rpx;
  381. }
  382. .baseUrl {
  383. border: 2rpx solid gray;
  384. width: 100%;
  385. margin: 20rpx auto;
  386. border-radius: 12rpx;
  387. align-items: center;
  388. input {
  389. width: 70%;
  390. padding: 16rpx 24rpx;
  391. }
  392. button {
  393. width: 30%;
  394. }
  395. }
  396. .item-user {
  397. margin: 32rpx;
  398. margin-top: 0;
  399. padding: 32rpx;
  400. background-color: #FFFFFF;
  401. align-items: center;
  402. .user-avatar {
  403. width: 128rpx;
  404. height: 128rpx;
  405. border-radius: 64rpx;
  406. background-color: #F1F2F3;
  407. justify-content: center;
  408. align-items: center;
  409. .label {
  410. font-size: 64rpx;
  411. }
  412. }
  413. .user-info {
  414. flex: 1;
  415. height: 96rpx;
  416. padding-left: 32rpx;
  417. .nickname {
  418. .label {
  419. font-weight: bold;
  420. font-size: 40rpx;
  421. }
  422. }
  423. .username {
  424. margin-top: 8rpx;
  425. .label {
  426. font-size: 32rpx;
  427. }
  428. }
  429. }
  430. }
  431. .add-user-btn {
  432. margin: 32rpx;
  433. padding: 32rpx;
  434. background-color: #FFFFFF;
  435. align-items: center;
  436. .icon {
  437. width: 128rpx;
  438. height: 128rpx;
  439. align-items: center;
  440. justify-content: center;
  441. background-color: #F1F2F3;
  442. border-radius: 64rpx;
  443. .label {
  444. color: #FFFFFF;
  445. font-size: 128rpx;
  446. }
  447. }
  448. .btn-label {
  449. flex: 1;
  450. padding-left: 32rpx;
  451. .label {
  452. font-size: 40rpx;
  453. }
  454. }
  455. }
  456. </style>