index.vue 11 KB

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