index.vue 12 KB

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