index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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 baseUrl = ref(null)
  103. const showGear = ref(0)
  104. const appInfo = ref({})
  105. const newAppInfo = ref({})
  106. const updateFlag = ref(true) // 是否更新标志,如果为false,不能登录
  107. const popup = ref(null)
  108. const showWrite = ref(0)
  109. const inputDialog = ref(null)
  110. const showInputDialog = ref(0)
  111. onLoad(() => {
  112. initBaseUrl();
  113. // getUser();
  114. setTimeout(doCheckUpdata, 500);
  115. })
  116. onReady(() => {
  117. })
  118. function doCheckUpdata() {
  119. checkUpdate().then(res => {
  120. updateFlag.value = res;
  121. console.log(res)
  122. if (!res) {
  123. uni.showModal({
  124. title: '更新',
  125. content: '发现新版本',
  126. showCancel: false,
  127. success: function(res) {
  128. if (res.confirm) {
  129. update();
  130. }
  131. }
  132. })
  133. }
  134. })
  135. }
  136. function checkUpdate() {
  137. uni.getSystemInfo({
  138. success: function(res) {
  139. appInfo.value = res;
  140. }
  141. });
  142. console.log(appInfo.value);
  143. // false 版本号不一致,更新,true不需要更新
  144. let flag = getAppInfoListByType(path.checkAppURL, {
  145. type: appInfo.value.osName
  146. }).then(res => {
  147. console.log(res);
  148. newAppInfo.value = res.rows[0];
  149. if (res.rows[0]) {
  150. return appInfo.value.appWgtVersion === newAppInfo.value.versionName;
  151. } else {
  152. return true;
  153. }
  154. })
  155. return flag;
  156. }
  157. function update() {
  158. upgrade.downloadInstallApp(path.updateAppURL + newAppInfo.value.url);
  159. console.log(newAppInfo.value)
  160. console.log(path.updateAppURL + newAppInfo.value.url)
  161. }
  162. function init() {
  163. uni.getStorageInfo({
  164. success: function(res) {
  165. for (let i = 0; i < res.keys.length; i++) {
  166. let storagekey = res.keys[i];
  167. console.log(storagekey)
  168. uni.getStorage({
  169. key: storagekey,
  170. success: function(res) {
  171. if (storagekey !== 'token' && storagekey !== '__DC_STAT_UUID' &&
  172. storagekey !== 'baseUrl') {
  173. getNickNameByUserName(storagekey).then((response) => {
  174. if (response.code == 200) {
  175. loggedUsers.value.push({
  176. userName: storagekey,
  177. password: res.data,
  178. nickName: response.msg
  179. })
  180. }
  181. })
  182. }
  183. if (storagekey == 'baseUrl') {
  184. baseUrl.value = JSON.parse(res.data).baseUrl;
  185. path.checkAppURL = JSON.parse(res.data).checkAppURL;
  186. path.updateAppURL = JSON.parse(res.data).updateAppURL;
  187. path.furnaceNoURL = JSON.parse(res.data).furnaceNoURL;
  188. }
  189. }
  190. });
  191. }
  192. }
  193. });
  194. }
  195. function initBaseUrl() {
  196. let urlList = {
  197. baseUrl: path.baseURL,
  198. checkAppURL: path.checkAppURL,
  199. updateAppURL: path.updateAppURL,
  200. furnaceNoURL: path.furnaceNoURL
  201. }
  202. uni.getStorage({
  203. key: 'baseUrl',
  204. fail: function() {
  205. uni.setStorageSync('baseUrl', JSON.stringify(urlList));
  206. },
  207. complete: function() {
  208. init();
  209. }
  210. });
  211. }
  212. function handleShowGear() {
  213. showGear.value += 1;
  214. }
  215. function handleShowWrite() {
  216. showWrite.value += 1;
  217. }
  218. function handleShowInputDialog(type) {
  219. showInputDialog.value += 1;
  220. if (showInputDialog.value > 4) {
  221. inputDialog.value.open(type);
  222. }
  223. }
  224. function dialogInputConfirm(val){
  225. if(val == 'admin888'){
  226. showWrite.value = true;
  227. }else {
  228. uni.showToast({
  229. icon: 'none',
  230. title: '密码错误'
  231. })
  232. }
  233. }
  234. function toggle(type) {
  235. showGear.value += 1;
  236. if (showGear.value > 5) {
  237. showGear.value = 0;
  238. }
  239. showWrite.value = false;
  240. showInputDialog.value = 0;
  241. popup.value.open(type);
  242. }
  243. function switchChange(e) {
  244. if (e.detail.value) {
  245. baseUrl.value = path.publicURL;
  246. path.checkAppURL = path.publicURL;
  247. path.updateAppURL = path.outUpdateAppURL;
  248. path.furnaceNoURL = path.outFurnaceNoURL;
  249. handleSetting();
  250. } else {
  251. baseUrl.value = path.innerURL;
  252. path.checkAppURL = path.innerURL;
  253. path.updateAppURL = path.innerUpdateAppURL;
  254. path.furnaceNoURL = path.innerFurnaceNoURL;
  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. }
  265. uni.setStorage({
  266. key: 'baseUrl',
  267. data: JSON.stringify(urlList),
  268. success: function() {
  269. uni.showToast({
  270. icon: "success",
  271. title: "设置成功"
  272. });
  273. doCheckUpdata();
  274. }
  275. });
  276. }
  277. const handleShowLoginDialog = (user) => {
  278. // 判断更新否,没更新不能登录
  279. if (!updateFlag.value) {
  280. uni.showToast({
  281. icon: 'none',
  282. title: '请更新后再登录'
  283. })
  284. setTimeout(doCheckUpdata, 500);
  285. } else {
  286. let _user = user ?? {}
  287. // 调用子组件中的方法
  288. loginDialog.value.open(_user)
  289. }
  290. }
  291. const handleSelectUser = (user) => {
  292. handleShowLoginDialog(user)
  293. }
  294. const handleLongPressUser = (user) => {
  295. console.log(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>