健康同学微信公众号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.

222 lines
5.7KB

  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="" />
  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 } from '@/config/models';
  46. import DialogService from '@/services/dialog-service';
  47. import ToastService from '@/services/toast-service';
  48. import APICommand from '@/api/command';
  49. export default {
  50. name: 'SubmenuList',
  51. props: {
  52. title: {
  53. type: String,
  54. default: ''
  55. },
  56. list: {
  57. type: Array,
  58. default: '' || []
  59. },
  60. rounded: {
  61. type: Boolean,
  62. default: null || false
  63. }
  64. },
  65. data() {
  66. return {
  67. dialog: {
  68. title: '',
  69. show: false
  70. }
  71. };
  72. },
  73. created() {},
  74. mounted() {},
  75. methods: {
  76. onItemClick(item) {
  77. console.log('点击的item', item);
  78. if (item.showType) {
  79. if (item.showType === 'newPage') {
  80. this.$router.push({
  81. name: `${item.routerName}`
  82. });
  83. } else if (item.showType === 'newDialog') {
  84. switch (item.routerName) {
  85. case 'remote':
  86. this.dialog.show = true;
  87. this.dialog.title = '远程控制';
  88. break;
  89. case 'version':
  90. this.$dialog.confirm({
  91. title: '当前版本信息',
  92. message: `${VersionModel}`,
  93. showCancelButton: false
  94. });
  95. break;
  96. case 'logout':
  97. this.$dialog
  98. .confirm({
  99. title: '确定要退出登录?',
  100. showCancelButton: true
  101. })
  102. .then(() => {})
  103. .catch(() => {});
  104. break;
  105. default:
  106. break;
  107. }
  108. }
  109. } else {
  110. this.$dialog.confirm({
  111. title: '提示',
  112. message: `功能开发中`,
  113. showCancelButton: false
  114. });
  115. }
  116. },
  117. onClick(model) {
  118. let val = null;
  119. let code = '0005'; // 定位0002 || 控制0005
  120. val = Number(model);
  121. this.sendCommand(code, JSON.stringify(val));
  122. },
  123. sendCommand(cmdCode, cmdValue) {
  124. ToastService.loading({
  125. message: '操作中'
  126. });
  127. APICommand.sendCommand({
  128. deviceId: this.$store.getters.deviceId,
  129. userId: this.$store.getters.userId,
  130. serialNo: this.$store.getters.serialNo,
  131. cmdCode,
  132. cmdValue
  133. })
  134. .then(res => {
  135. let item = res.data;
  136. if (item.stateCode == 1) {
  137. ToastService.success({
  138. message: '操作成功'
  139. });
  140. } else if (cmdCode === '0005') {
  141. DialogService.confirm({ title: '设备离线,操作失败' });
  142. } else {
  143. DialogService.confirm({ title: '操作失败', message: '设备不在线' });
  144. }
  145. })
  146. .catch(() => {
  147. ToastService.clear();
  148. })
  149. .finally(() => {
  150. ToastService.clear();
  151. });
  152. }
  153. }
  154. };
  155. </script>
  156. <style scoped lang="scss">
  157. .submenu-list {
  158. height: 100%;
  159. width: 100%;
  160. position: relative;
  161. .header {
  162. position: relative;
  163. font-weight: bold;
  164. padding: 10px 20px;
  165. @include flexbox(flex-start, center, row, wrap);
  166. .left {
  167. p {
  168. font-size: 36px;
  169. font-weight: bold;
  170. }
  171. }
  172. }
  173. .main {
  174. position: relative;
  175. @include flexbox(flex-start, center, row, wrap);
  176. width: 100%;
  177. .list {
  178. position: relative;
  179. padding-left: 20px;
  180. display: grid;
  181. grid-template-columns: repeat(4, auto);
  182. grid-gap: 20px;
  183. .item {
  184. position: relative;
  185. /* height: 140px; */
  186. /* max-width: 180px; */
  187. /* padding: 0 20px; */
  188. @include flexbox(center, center, column, nowrap);
  189. .img-icon-con {
  190. height: 110px;
  191. width: 110px;
  192. @include flexbox(space-around, center, column, wrap);
  193. background-color: #fff;
  194. img {
  195. height: 110px;
  196. widows: 110px;
  197. /* border-radius: 50%; */
  198. object-fit: cover;
  199. }
  200. }
  201. .text {
  202. @include flexbox(space-around, center, column, nowrap);
  203. padding: 5px 0;
  204. font-size: 24px;
  205. font-weight: 400;
  206. }
  207. }
  208. }
  209. }
  210. .dialog {
  211. height: 300px;
  212. padding: 0 80px;
  213. @include flexbox(center, center, column, wrap);
  214. .van-cell {
  215. border-bottom: 1px solid $border_color;
  216. }
  217. }
  218. }
  219. /* @import url(); 引入css类 */
  220. </style>