ComputerDetail.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: ComputerDetail.vue
  4. * @Description: 电脑信息-当前
  5. * @Author: xinyan
  6. */
  7. import { useResponse } from '/@/utils/useResponse';
  8. import { ComputerCurrentColumns, ComputerPastColumns } from '/@/views/computer-information/useColumns';
  9. import * as api from '../api';
  10. import { Edit, Picture as IconPicture } from '@element-plus/icons-vue';
  11. import { useTableData } from '/@/utils/useTableData';
  12. import { usePagination } from '/@/utils/usePagination';
  13. import EditComputerInfo from '/@/views/computer-information/components/EditComputerInfo.vue';
  14. import { ref } from 'vue';
  15. import { getCurrentTableData, getPastTableData } from '../api';
  16. const route = useRoute();
  17. const id = route.query.id;
  18. // const computerNumber = route.query.computerNumber;
  19. const computerOverview: any = ref([]);
  20. const overviewLoading = ref();
  21. const isDrawerVisible = ref(false);
  22. const shopOptions = ref([]);
  23. const userOptions = ref([]);
  24. const currentView = ref('current');
  25. // const { tableOptions, handlePageChange } = usePagination(fetchComputerData);
  26. const gridOptions: any = reactive({
  27. border: 'inner',
  28. round: true,
  29. stripe: true,
  30. currentRowHighLight: true,
  31. height: 700,
  32. toolbarConfig: {
  33. custom: true,
  34. slots: {
  35. buttons: 'toolbar_buttons',
  36. // tools: 'toolbar_tools'
  37. },
  38. },
  39. rowConfig: {
  40. isHover: true,
  41. },
  42. columnConfig: {
  43. resizable: true,
  44. },
  45. pagerConfig: {
  46. total: 0,
  47. currentPage: 1,
  48. pageSize: 20,
  49. },
  50. loading: false,
  51. loadingConfig: {
  52. icon: 'vxe-icon-indicator roll',
  53. text: '正在拼命加载中...',
  54. },
  55. columns: ComputerCurrentColumns,
  56. data: [],
  57. });
  58. async function editItem() {
  59. isDrawerVisible.value = true; // 显示 Drawer
  60. }
  61. async function fetchComputerDetailOverview() {
  62. const res = await useResponse(id, api.getComputerDetailOverview, overviewLoading);
  63. computerOverview.value = res.data;
  64. }
  65. const gridEvents = {
  66. pageChange({ currentPage, pageSize }) {
  67. console.log("=>(ComputerDetail.vue:73) pageSize", pageSize);
  68. console.log("=>(ComputerDetail.vue:73) currentPage", currentPage);
  69. if (gridOptions.pagerConfig) {
  70. gridOptions.pagerConfig.currentPage = currentPage;
  71. gridOptions.pagerConfig.pageSize = pageSize;
  72. fetchComputerData(currentView.value);
  73. }
  74. }
  75. };
  76. // 当前信息、历史记录
  77. async function fetchComputerData(view) { // 默认为当前视图
  78. const query = {
  79. page: gridOptions.pagerConfig.currentPage,
  80. limit: gridOptions.pagerConfig.pageSize,
  81. computerNumber : computerOverview.value.computerNumber,
  82. };
  83. switch (view) {
  84. case 'current':
  85. gridOptions.columns = ComputerCurrentColumns;
  86. currentView.value = 'current';
  87. const resp = await getCurrentTableData(query);
  88. gridOptions.data = resp.data;
  89. gridOptions.pagerConfig.total = resp.total;
  90. // await useTableData(api.getCurrentTableData, query, gridOptions);
  91. break;
  92. case 'history':
  93. gridOptions.columns = ComputerPastColumns;
  94. currentView.value = 'history';
  95. query.id = id;
  96. // await useTableData(api.getPastTableData, query, gridOptions);
  97. const ret = await getPastTableData(query);
  98. gridOptions.data = ret.data;
  99. gridOptions.pagerConfig.total = ret.total;
  100. break;
  101. }
  102. }
  103. function switchView(view) {
  104. if (view !== currentView.value) {
  105. gridOptions.pagerConfig.currentPage = 1;
  106. gridOptions.pagerConfig.pageSize = 20;
  107. fetchComputerData(view);
  108. }
  109. }
  110. function handleRefresh() {
  111. fetchComputerDetailOverview();
  112. fetchComputerData()
  113. }
  114. async function fetchShopOptions() {
  115. try {
  116. const resp = await useResponse(null, api.getShopList);
  117. shopOptions.value = resp.data.map((item: any) => {
  118. return { value: item.id, label: item.platformNumber };
  119. });
  120. } catch (e) {
  121. console.log('error', e);
  122. }
  123. }
  124. async function fetchUserOptions() {
  125. try {
  126. const resp = await useResponse(null, api.getUserList);
  127. userOptions.value = resp.data.map((item: any) => {
  128. return { value: item.id, label: item.name };
  129. });
  130. } catch (e) {
  131. console.log('error', e);
  132. }
  133. }
  134. const getImageSrc = () => {
  135. // 如果 `images` 有值,则返回第一张图片的 URL;否则返回占位图
  136. return computerOverview.value.images && computerOverview.value.images.length > 0
  137. ? computerOverview.value.images[0].image_url
  138. : 'https://via.placeholder.com/150';
  139. };
  140. // 表格样式
  141. const cellStyle = () => {
  142. return {
  143. fontSize: '12px',
  144. fontWeight: '600',
  145. };
  146. };
  147. const headerCellStyle = () => {
  148. return {
  149. fontSize: '12px',
  150. };
  151. };
  152. onMounted(async () => {
  153. await fetchComputerDetailOverview(); // 等待获取详情
  154. await fetchComputerData(currentView.value); // 获取电脑数据
  155. await fetchShopOptions(); // 获取店铺选项
  156. await fetchUserOptions(); // 获取用户选项
  157. });
  158. </script>
  159. <template>
  160. <div class="p-2.5">
  161. <!-- overview-card -->
  162. <el-card v-loading="overviewLoading" body-class="flex items-center" shadow="hover" style="border: none">
  163. <el-image :src="getImageSrc()" class="mr-7 rounded-2xl" style="height: 100px; width: 100px; object-fit: contain">
  164. <template #error>
  165. <div class="mr-3.5 flex items-center justify-center text-5xl" style="height: 100px; width: 100px; background-color: #f5f5f5">
  166. <el-icon>
  167. <icon-picture />
  168. </el-icon>
  169. </div>
  170. </template>
  171. </el-image>
  172. <el-button :icon="Edit" link type="warning" @click="editItem"></el-button>
  173. <el-col :span="18">
  174. <div class="info-container text-lg">
  175. <div class="info-column">
  176. <div class="font-semibold">
  177. 电脑编号:
  178. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ computerOverview.computerNumber }}</span>
  179. </div>
  180. <div class="font-semibold">
  181. 所属店铺:
  182. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ computerOverview.platformNumber }}</span>
  183. </div>
  184. <div class="font-semibold">
  185. 工位号:
  186. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ computerOverview.station }}</span>
  187. </div>
  188. <div class="font-semibold">
  189. IP地址:
  190. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ computerOverview.ipaddress }}</span>
  191. </div>
  192. </div>
  193. <div class="info-column">
  194. <div class="font-semibold">
  195. 使用人:
  196. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ computerOverview.userName }}</span>
  197. </div>
  198. <div class="font-semibold">
  199. 电脑类型:
  200. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ computerOverview.computerType }}</span>
  201. </div>
  202. <div class="font-semibold">
  203. MAC地址:
  204. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ computerOverview.macaddress }}</span>
  205. </div>
  206. </div>
  207. </div>
  208. </el-col>
  209. </el-card>
  210. <!-- table-card -->
  211. <el-card body-style="padding-top: 10px" class="mt-2.5" shadow="hover" style="border: none">
  212. <vxe-grid :cell-style="cellStyle" :header-cell-style="headerCellStyle" v-bind="gridOptions" v-on="gridEvents">
  213. <template #toolbar_buttons>
  214. <el-button :type="currentView === 'current' ? 'primary' : 'default'" @click="switchView('current')"> 当前信息 </el-button>
  215. <el-button :type="currentView === 'history' ? 'primary' : 'default'" @click="switchView('history')"> 历史记录 </el-button>
  216. </template>
  217. </vxe-grid>
  218. </el-card>
  219. <!-- 编辑 Drawer -->
  220. <EditComputerInfo
  221. v-if="isDrawerVisible"
  222. v-model="isDrawerVisible"
  223. :computerOverview
  224. :computerNumber="computerOverview.computerNumber"
  225. :shopOptions="shopOptions"
  226. :userOptions="userOptions"
  227. @refresh="handleRefresh"
  228. />
  229. </div>
  230. </template>
  231. <style lang="scss" scoped>
  232. .info-container {
  233. display: flex;
  234. justify-content: space-between;
  235. }
  236. .info-column {
  237. flex: 1;
  238. padding: 0 10px;
  239. }
  240. p {
  241. margin: 5px 0;
  242. }
  243. </style>