device-config.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="device-config-container">
  3. <NavBar title="设备参数模板" @back="goBack" />
  4. <!-- 配置列表 -->
  5. <view class="config-list">
  6. <view
  7. v-for="config in configList"
  8. :key="config.id"
  9. class="config-item"
  10. @click="navigateToEditConfig(config.id)"
  11. >
  12. <view class="config-id-section">
  13. <text class="id-badge">ID: {{ config.id }}</text>
  14. </view>
  15. <view class="config-main-info">
  16. <text class="config-name">{{ config.name }}</text>
  17. <text class="config-desc">{{ config.remark || '无描述' }}</text>
  18. </view>
  19. <view class="config-action">
  20. <AppIcon name="chevron-right" size="18" color="#CCCCCC" />
  21. </view>
  22. </view>
  23. </view>
  24. <!-- 空状态 -->
  25. <view class="empty-state" v-if="configList.length === 0 && !loading">
  26. <view class="empty-icon-wrapper">
  27. <AppIcon name="settings" size="48" color="#BFBFBF" />
  28. </view>
  29. <text class="empty-text">暂无设备配置</text>
  30. <text class="empty-desc">点击右上角添加配置</text>
  31. </view>
  32. <!-- 悬浮添加按钮 -->
  33. <view class="fab-add" @click="navigateToAddConfig">
  34. <AppIcon name="plus" size="28" color="#FFFFFF" />
  35. </view>
  36. <!-- 加载状态 -->
  37. <view class="loading-overlay" v-if="loading">
  38. <view class="loading-spinner"></view>
  39. <text class="loading-text">加载中...</text>
  40. </view>
  41. </view>
  42. </template>
  43. <script setup>
  44. import { ref } from 'vue'
  45. import { onShow } from '@dcloudio/uni-app'
  46. import { getDeviceConfigList } from '../../api/device.js'
  47. import { showToast } from '../../utils/index.js'
  48. const configList = ref([])
  49. const loading = ref(false)
  50. const stationId = ref('') // 可选过滤
  51. // 加载设备配置列表
  52. const loadDeviceConfigs = async () => {
  53. if (loading.value) return
  54. loading.value = true
  55. try {
  56. const res = await getDeviceConfigList({
  57. page: 1,
  58. pageSize: 100,
  59. stationId: stationId.value
  60. })
  61. if (res && res.code === 200) {
  62. // 适配分页结构 list, records 或直接数组
  63. const data = res.data
  64. configList.value = data.list || data.records || (Array.isArray(data) ? data : [])
  65. console.log('设备配置列表加载成功:', configList.value)
  66. } else {
  67. showToast(res.message || '获取配置列表失败')
  68. }
  69. } catch (error) {
  70. console.error('加载设备配置失败:', error)
  71. showToast('网络请求失败,请检查网络')
  72. } finally {
  73. loading.value = false
  74. }
  75. }
  76. // 页面每次显示时(包括从编辑页返回)都刷新数据
  77. onShow(() => {
  78. loadDeviceConfigs()
  79. })
  80. // 导航到添加配置页面
  81. const navigateToAddConfig = () => {
  82. uni.navigateTo({
  83. url: '/pages/setting/device-config-detail'
  84. })
  85. }
  86. // 导航到编辑配置页面
  87. const navigateToEditConfig = (configId) => {
  88. uni.navigateTo({
  89. url: `/pages/setting/device-config-detail?id=${configId}`
  90. })
  91. }
  92. // 返回上一页
  93. const goBack = () => {
  94. uni.navigateBack()
  95. }
  96. </script>
  97. <style scoped>
  98. .device-config-container {
  99. min-height: 100vh;
  100. background-color: #F5F7FA;
  101. padding-bottom: 180rpx; /* 关键:间距改在这里,确保滚动到底部不被按钮遮挡 */
  102. box-sizing: border-box;
  103. }
  104. /* 顶部导航栏 */
  105. .header-nav {
  106. display: flex;
  107. align-items: center;
  108. justify-content: space-between;
  109. padding-top: calc(24rpx + var(--status-bar-height));
  110. padding-right: 30rpx;
  111. padding-bottom: 24rpx;
  112. padding-left: 30rpx;
  113. background: #C6171E;
  114. box-shadow: 0 4rpx 16rpx rgba(198, 23, 30, 0.2);
  115. }
  116. .nav-left {
  117. width: 180rpx; /* 增加宽度以平衡右侧胶囊按钮空间 */
  118. display: flex;
  119. align-items: center;
  120. }
  121. .back-icon {
  122. font-size: 40rpx;
  123. color: #FFFFFF;
  124. font-weight: 600;
  125. }
  126. .nav-title {
  127. font-size: 34rpx;
  128. color: #FFFFFF;
  129. font-weight: 600;
  130. flex: 1;
  131. text-align: center;
  132. white-space: nowrap;
  133. }
  134. .nav-right {
  135. width: 180rpx;
  136. }
  137. /* 悬浮添加按钮 */
  138. .fab-add {
  139. position: fixed;
  140. left: 50%;
  141. transform: translateX(-50%);
  142. bottom: calc(60rpx + env(safe-area-inset-bottom));
  143. width: 110rpx;
  144. height: 110rpx;
  145. background: #C6171E;
  146. border-radius: 50%;
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. box-shadow: 0 10rpx 30rpx rgba(198, 23, 30, 0.4);
  151. z-index: 99;
  152. transition: all 0.3s;
  153. }
  154. .fab-add:active {
  155. transform: translateX(-50%) scale(0.9);
  156. box-shadow: 0 4rpx 15rpx rgba(198, 23, 30, 0.3);
  157. }
  158. .plus-icon {
  159. font-size: 70rpx;
  160. color: #FFFFFF;
  161. font-weight: 300;
  162. margin-top: -6rpx;
  163. }
  164. /* 配置列表 */
  165. .config-list {
  166. margin: 20rpx;
  167. background-color: #FFFFFF;
  168. border-radius: 16rpx;
  169. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  170. /* 移除了内部 padding-bottom */
  171. }
  172. .config-item {
  173. display: flex;
  174. align-items: center;
  175. height: 140rpx; /* 固定高度确保等高 */
  176. padding: 0 30rpx;
  177. border-bottom: 1rpx solid #F0F0F0;
  178. box-sizing: border-box;
  179. }
  180. .config-item:last-child {
  181. border-bottom: none;
  182. }
  183. .config-id-section {
  184. margin-right: 24rpx;
  185. flex-shrink: 0;
  186. }
  187. .id-badge {
  188. display: inline-block;
  189. font-size: 22rpx;
  190. color: #C6171E;
  191. background-color: rgba(198, 23, 30, 0.1);
  192. padding: 6rpx 16rpx;
  193. border-radius: 8rpx;
  194. font-weight: 600;
  195. min-width: 80rpx;
  196. text-align: center;
  197. }
  198. .config-main-info {
  199. flex: 1;
  200. overflow: hidden; /* 必须,用于文本溢出省略 */
  201. display: flex;
  202. flex-direction: column;
  203. justify-content: center;
  204. }
  205. .config-name {
  206. font-size: 30rpx;
  207. color: #1A1A1A;
  208. font-weight: 600;
  209. margin-bottom: 6rpx;
  210. white-space: nowrap;
  211. overflow: hidden;
  212. text-overflow: ellipsis;
  213. }
  214. .config-desc {
  215. font-size: 24rpx;
  216. color: #999999;
  217. white-space: nowrap;
  218. overflow: hidden;
  219. text-overflow: ellipsis;
  220. }
  221. .config-action {
  222. margin-left: 20rpx;
  223. flex-shrink: 0;
  224. }
  225. .arrow {
  226. font-size: 30rpx;
  227. color: #CCCCCC;
  228. }
  229. /* 空状态 */
  230. .empty-state {
  231. display: flex;
  232. flex-direction: column;
  233. align-items: center;
  234. justify-content: center;
  235. padding: 120rpx 0;
  236. color: #999999;
  237. }
  238. .empty-icon {
  239. font-size: 120rpx;
  240. margin-bottom: 32rpx;
  241. opacity: 0.5;
  242. }
  243. .empty-text {
  244. font-size: 28rpx;
  245. margin-bottom: 16rpx;
  246. }
  247. .empty-desc {
  248. font-size: 24rpx;
  249. }
  250. /* 加载状态 */
  251. .loading-overlay {
  252. position: fixed;
  253. top: 0;
  254. left: 0;
  255. right: 0;
  256. bottom: 0;
  257. background-color: rgba(0, 0, 0, 0.4);
  258. backdrop-filter: blur(2px);
  259. display: flex;
  260. flex-direction: column;
  261. align-items: center;
  262. justify-content: center;
  263. z-index: 999;
  264. }
  265. .loading-spinner {
  266. font-size: 64rpx;
  267. animation: spin 1s linear infinite;
  268. margin-bottom: 32rpx;
  269. color: #fff;
  270. }
  271. .loading-text {
  272. font-size: 28rpx;
  273. color: #fff;
  274. }
  275. </style>