index.vue 11 KB

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