chengxiangling
2025-05-16 af1c9e588f1de0240390648f9bb56aa486870aff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<template>
    <div class="app-container">
        <el-row>
            <el-col :span="24">
                <div slot="header" class="clearfix">
                    <span><b>表格展示</b></span>
                </div>
                <div style="width: 100%;display: flex;flex-direction: column;align-items: center;">
 
                    <!--查询条件-->
                    <!-- <el-form ref="queryForm" style="width: 100%" inline>
                    <el-form-item label="接口名" style="float: left" class="form_btn ">
                        <el-input v-model="selectItem.name" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item style="float: right" class="form_btn ">
                        <el-button icon="el-icon-search" @click="alert('暂时无法搜索')">搜索</el-button>
                    </el-form-item>
                    </el-form> -->
 
                    <HxlhTable
                        style="width: 100%"
                        :columns="columns"
                        :data="tableData"
                        :loading="loading"
                        :page="page"
                        @changePageNo="changePageNo"
                        @changePageSize="changePageSize"
                    >
                    </HxlhTable>
            </div>
            </el-col>
        </el-row>
    </div>
</template>
  
<script setup>
    
import { ref, reactive, onMounted } from 'vue';
import HxlhTable from '@/components/HxlhTable'
 
// 搜索使用组件
const selectItem = reactive({
  name: ''
});
 
// 表格 - 项目所有数据
const tableData = ref([
  { code: '111', name: '张三', sex: '男' },
  { code: '222', name: '李四', sex: '男' },
  { code: '333', name: '王五', sex: '男' },
  { code: '444', name: '赵六', sex: '女' }
]);
 
const mockData = ref([]);
 
for (let i = 0; i < 1000; i++) {
    tableData.value.push({
      code: `new${i + 1}`,
      name: `新人${i + 1}`,
      sex: '未知'
    });
  }
 
 
 
// 表格配置
const columns = ref([
  { type: 'seq', title: '序号', width: 60 },
  {
    title: '编号',
    field: 'code'
  },
  {
    title: '名称',
    field: 'name'
  },
  {
    title: '性别',
    field: 'sex'
  }
]);
 
// 表格缓冲
const loading = ref(false);
 
// 分页属性
const page = ref({
  total: 1004,
  current: 1,
  size: 10
});
 
const changePageNo = async (currentPage) => {
  console.log(currentPage);
  page.value.current = currentPage;
  // await fetchData();
}
 
const changePageSize = async (pageSize) => {
  console.log(pageSize);
  page.value.current = 1;
  page.value.size = pageSize;
  // await fetchData();
}
 
// 模拟数据加载
/* const fetchData = () => {
  // 这里可以替换为实际的 API 请求
  return new Promise((resolve) => {
      const current = page.value.current;
      const pageSize = page.value.size;
      const start = (current - 1) * pageSize;
      let end = start + pageSize;
      if(end > tableData.value.length){
        end = tableData.value.length;
      }
      const data = [];
      for (let i = start; i < end; i++) {
        console.log(tableData.value[i]);
        data.push(tableData.value[i]);
      }
      // 模拟总记录数
      // const total = 100;
      mockData.value = data;
      // pagerConfig.value.total = total;
      resolve();
  });
}; */
 
// 生命周期钩子,替代 mounted
onMounted(() => {
  // 这里可以放置原来 mounted 钩子中的代码
});
 
// 初始化数据
// const initData = async () => {
//   await fetchData();
// };
 
// initData();
</script>
  
<style scoped="scoped">
#view {
    width: 100%;
    height: 100%;
    padding: 0px;
    margin: 0px;
}
 
.box-card {
    width: 480px;
}
</style>