index.vue 11 KB

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