index.vue 11 KB

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