健康同学微信公众号h5项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SubmenuList.vue 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <!-- -->
  2. <template>
  3. <div class="submenu-list">
  4. <div class="header">
  5. <div class="left">
  6. <p>{{ title }}</p>
  7. </div>
  8. <div class="right"></div>
  9. </div>
  10. <div class="main">
  11. <div class="list">
  12. <div class="item" v-for="(item, index) in list" :key="index" @click="onItemClick(item)">
  13. <div class="img-icon-con" :style="{ borderRadius: rounded ? '50%' : '', backgroundColor: '#fff' }">
  14. <img :src="item.imgPath" alt="" :style="{ borderRadius: rounded ? '50%' : '', backgroundColor: '#fff' }" />
  15. </div>
  16. <div class="text">
  17. <span>{{ item.text }}</span>
  18. </div>
  19. </div>
  20. <slot name="addDevice"></slot>
  21. </div>
  22. </div>
  23. <!-- <div class="footer"></div> -->
  24. <van-dialog v-model="dialog.show" :title="dialog.title" confirm-button-text="关闭">
  25. <template #default>
  26. <div class="dialog">
  27. <van-cell value="重启" border @click="onClick(3)">
  28. <!-- 使用 title 插槽来自定义标题 -->
  29. <!-- <template #right-icon>
  30. <van-icon name="search" class="search-icon" />
  31. </template> -->
  32. </van-cell>
  33. <van-cell value="关机" border @click="onClick(3)">
  34. <!-- 使用 title 插槽来自定义标题 -->
  35. <!-- <template #right-icon>
  36. <van-icon name="search" class="search-icon" />
  37. </template> -->
  38. </van-cell>
  39. </div>
  40. </template>
  41. </van-dialog>
  42. </div>
  43. </template>
  44. <script>
  45. import { VersionModel, WechatHomeModel } from '@/config/models';
  46. import DialogService from '@/services/dialog-service';
  47. import ToastService from '@/services/toast-service';
  48. import APICommand from '@/api/command';
  49. import APIUser from '@/api/user';
  50. import AppId from '@/config/appId';
  51. export default {
  52. name: 'SubmenuList',
  53. props: {
  54. title: {
  55. type: String,
  56. default: ''
  57. },
  58. list: {
  59. type: Array,
  60. default: '' || []
  61. },
  62. rounded: {
  63. type: Boolean,
  64. default: null || false
  65. }
  66. },
  67. data() {
  68. return {
  69. dialog: {
  70. title: '',
  71. show: false
  72. }
  73. };
  74. },
  75. created() {},
  76. mounted() {},
  77. methods: {
  78. onItemClick(item) {
  79. console.log('点击的item', item);
  80. let that = this;
  81. if (item.showType) {
  82. if (item.showType === 'newPage') {
  83. if (item.routerName === 'personInfos') {
  84. this.$store.commit('personId', item.id);
  85. this.$router.push({
  86. name: `${item.routerName}`,
  87. query: {
  88. update: true,
  89. toRouter: 'Myself',
  90. from: 'Myself'
  91. }
  92. });
  93. } else {
  94. this.$router.push({
  95. name: `${item.routerName}`
  96. });
  97. }
  98. } else if (item.showType === 'newDialog') {
  99. switch (item.routerName) {
  100. case 'remote':
  101. this.dialog.show = true;
  102. this.dialog.title = '远程控制';
  103. break;
  104. case 'version':
  105. this.$dialog.confirm({
  106. title: '当前版本信息',
  107. message: `${VersionModel}`,
  108. showCancelButton: false
  109. });
  110. break;
  111. case 'logout':
  112. this.$dialog
  113. .confirm({
  114. title: '确定要退出登录?',
  115. showCancelButton: true
  116. })
  117. .then(() => {
  118. that.logout();
  119. })
  120. .catch(() => {});
  121. break;
  122. default:
  123. break;
  124. }
  125. }
  126. } /* else {
  127. this.$dialog.confirm({
  128. title: '提示',
  129. message: `功能开发中`,
  130. showCancelButton: false
  131. });
  132. } */
  133. },
  134. onClick(model) {
  135. let val = null;
  136. let code = '0005'; // 定位0002 || 控制0005
  137. val = Number(model);
  138. this.sendCommand(code, JSON.stringify(val));
  139. },
  140. sendCommand(cmdCode, cmdValue) {
  141. ToastService.loading({
  142. message: '操作中'
  143. });
  144. APICommand.sendCommand({
  145. deviceId: this.$store.getters.deviceId,
  146. userId: this.$store.getters.userId,
  147. serialNo: this.$store.getters.serialNo,
  148. cmdCode,
  149. cmdValue
  150. })
  151. .then(res => {
  152. let item = res.data;
  153. if (item.stateCode == 1) {
  154. ToastService.success({
  155. message: '操作成功'
  156. });
  157. } else if (cmdCode === '0005') {
  158. DialogService.confirm({ title: '设备离线,操作失败' });
  159. } else {
  160. DialogService.confirm({ title: '操作失败', message: '设备不在线' });
  161. }
  162. })
  163. .catch(() => {
  164. ToastService.clear();
  165. })
  166. .finally(() => {
  167. ToastService.clear();
  168. });
  169. },
  170. // 退出登录
  171. logout() {
  172. APIUser.loginOut({
  173. headers: { AuthKey: 'key1' },
  174. body: {
  175. userId: this.$store.getters.userId,
  176. openId: this.$store.getters.openId || '',
  177. AppId: AppId
  178. }
  179. }).then(res => {
  180. console.log(res);
  181. if (res.data.stateCode === 1 || res.data.stateCode === 0) {
  182. // success
  183. //清空数据
  184. this.$own.clearLocalStorage(this.$store);
  185. this.$store.commit('isRegister', 'true');
  186. this.$store.commit('isLogin', 'true');
  187. // this.$router.push({ name: "login" }); // 退出路由至登录页面:需要后端将登录接口分开为登录和code消费接口,之后,才可路由回登录页面
  188. window.location.href = WechatHomeModel[process.env.NODE_ENV];
  189. } else {
  190. DialogService.confirm({ title: '服务器繁忙,请稍后操作' });
  191. }
  192. });
  193. }
  194. }
  195. };
  196. </script>
  197. <style scoped lang="scss">
  198. .submenu-list {
  199. height: 100%;
  200. width: 100%;
  201. position: relative;
  202. .header {
  203. position: relative;
  204. font-weight: bold;
  205. padding: 10px 20px;
  206. @include flexbox(flex-start, center, row, wrap);
  207. .left {
  208. p {
  209. font-size: 36px;
  210. font-weight: bold;
  211. }
  212. }
  213. }
  214. .main {
  215. position: relative;
  216. @include flexbox(flex-start, center, row, wrap);
  217. width: 100%;
  218. .list {
  219. position: relative;
  220. padding-left: 20px;
  221. display: grid;
  222. grid-template-columns: repeat(4, auto);
  223. grid-gap: 50px;
  224. .item {
  225. position: relative;
  226. /* height: 140px; */
  227. /* max-width: 180px; */
  228. /* padding: 0 20px; */
  229. @include flexbox(center, center, column, nowrap);
  230. .img-icon-con {
  231. height: 110px;
  232. width: 110px;
  233. @include flexbox(space-around, center, column, wrap);
  234. background-color: #fff;
  235. img {
  236. height: 110px;
  237. widows: 110px;
  238. /* border-radius: 50%; */
  239. object-fit: cover;
  240. }
  241. }
  242. .text {
  243. @include flexbox(space-around, center, column, nowrap);
  244. padding: 5px 0;
  245. font-size: 24px;
  246. font-weight: 400;
  247. }
  248. }
  249. }
  250. }
  251. .dialog {
  252. height: 300px;
  253. padding: 0 80px;
  254. @include flexbox(center, center, column, wrap);
  255. .van-cell {
  256. border-bottom: 1px solid $border_color;
  257. }
  258. }
  259. }
  260. /* @import url(); 引入css类 */
  261. </style>