pathList.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div class="store-page">
  3. <Breadcrumb />
  4. <a-card title="路径列表">
  5. <AppQueryFilter>
  6. <a-row class="query-row">
  7. <a-col :flex="'1000px'" class="query-main">
  8. <a-form class="queryForm app-query-form" :model="queryData" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }"
  9. label-align="left">
  10. <a-row :gutter="16">
  11. <a-col :span="8">
  12. <a-form-item field="area" label="跑区">
  13. <a-select v-model="queryData.area" placeholder="请选择乐跑跑区" default-value="">
  14. <a-option value="">所有</a-option>
  15. <a-option v-for="(item, index) in areas" :key="index" :value="item">
  16. {{ item }}
  17. </a-option>
  18. </a-select>
  19. </a-form-item>
  20. </a-col>
  21. <a-col :span="8">
  22. <a-form-item field="path_id" label="路径ID">
  23. <a-input-number v-model="queryData.path_id" placeholder="请输入路径ID" :step="1"
  24. :precision="0" />
  25. </a-form-item>
  26. </a-col>
  27. <a-col :span="8">
  28. <a-form-item field="min_distance" label="最短距离">
  29. <a-input-number v-model="queryData.min_distance" placeholder="请输入最短距离" :step="0.01"
  30. :precision="2" />
  31. </a-form-item>
  32. </a-col>
  33. <a-col :span="8">
  34. <a-form-item field="max_distance" label="最长距离">
  35. <a-input-number v-model="queryData.max_distance" placeholder="请输入最长距离" :step="0.01"
  36. :precision="2" />
  37. </a-form-item>
  38. </a-col>
  39. <a-col :span="8">
  40. <a-form-item field="area" label="状态">
  41. <a-select v-model="queryData.state" :options="state" placeholder="请选择路径状态"
  42. :default-value="-1" />
  43. </a-form-item>
  44. </a-col>
  45. </a-row>
  46. </a-form>
  47. </a-col>
  48. <a-divider class="query-divider" style="height: 84px" direction="vertical" />
  49. <a-col :flex="1" class="app-query-actions">
  50. <a-space class="query-actions-space" direction="vertical" :size="18">
  51. <a-button type="primary" @click="search">
  52. <template #icon>
  53. <icon-search />
  54. </template>
  55. 搜索
  56. </a-button>
  57. <a-button @click="reset">
  58. <template #icon>
  59. <icon-refresh />
  60. </template>
  61. 重置
  62. </a-button>
  63. </a-space>
  64. </a-col>
  65. </a-row>
  66. </AppQueryFilter>
  67. <a-table :bordered="false" :data="data" stripe hoverable column-resizable class="table" :loading="loading" :columns="columns"
  68. :pagination="{
  69. showPageSize: true,
  70. showJumper: true,
  71. showTotal: true,
  72. pageSize: pagination.pagesize,
  73. current: pagination.current,
  74. total: pagination.total
  75. }" @page-change="handlePageChange" @page-size-change="handlePageSizeChange">
  76. <template #time="{ record }">
  77. {{ formatSecondsToMinSec(record.time) }}
  78. </template>
  79. <template #state="{ record }">
  80. <a-tag color="blue" v-if="!record.state">待审核</a-tag>
  81. <a-tag color="green" v-else-if="record.state === 1">审核通过</a-tag>
  82. <a-tag color="red" v-else-if="record.state === 2">审核失败</a-tag>
  83. </template>
  84. <template #optional="{ record }">
  85. <a-button @click="$router.push(`/path/detail/${record.id}`)">查看详情</a-button>
  86. </template>
  87. </a-table>
  88. </a-card>
  89. </div>
  90. </template>
  91. <script setup>
  92. import { ref, reactive, onMounted } from 'vue'
  93. import { GetPathList } from '@/api/pathData'
  94. import { Notification } from '@arco-design/web-vue'
  95. const queryData = reactive({
  96. area: '',
  97. path_id: '',
  98. min_distance: 1.60,
  99. max_distance: 10.00,
  100. state: -1
  101. })
  102. const pagination = reactive({
  103. total: 0,
  104. current: 1, // 默认从第1页开始
  105. pagesize: 20
  106. })
  107. const loading = ref(false)
  108. const data = ref([])
  109. const state = [
  110. { label: '全部', value: -1 }, { label: '待审核', value: 0 }, { label: '审核通过', value: 1 }, { label: '审核失败', value: 2 }
  111. ]
  112. const areas = ["学府大道校区", "南山校区"]
  113. const columns = [{
  114. title: 'ID',
  115. dataIndex: 'id',
  116. }, {
  117. title: '跑区',
  118. dataIndex: 'run_zone_name',
  119. }, {
  120. title: '跑步距离(Km)',
  121. dataIndex: 'distance',
  122. }, {
  123. title: '用时',
  124. slotName: 'time'
  125. }, {
  126. title: '配速',
  127. dataIndex: 'speed',
  128. }, {
  129. title: '使用次数',
  130. dataIndex: 'count',
  131. }, {
  132. title: '状态',
  133. slotName: 'state'
  134. }, {
  135. title: '操作',
  136. slotName: 'optional'
  137. }]
  138. const search = () => {
  139. pagination.current = 1
  140. getPathList()
  141. }
  142. const reset = () => {
  143. pagination.current = 1
  144. queryData.area = ''
  145. queryData.state = -1
  146. queryData.path_id = ''
  147. queryData.min_distance = 1.60
  148. queryData.max_distance = 10.00
  149. getPathList()
  150. }
  151. const getPathList = async () => {
  152. try {
  153. loading.value = true
  154. const reqData = {
  155. ...queryData,
  156. pagesize: pagination.pagesize,
  157. current: pagination.current
  158. }
  159. const res = await GetPathList(reqData)
  160. if (!res || res.code !== 0)
  161. return Notification.error({
  162. title: '获取路径数据失败!',
  163. content: res?.msg ?? '请稍后再试'
  164. })
  165. data.value = res.data
  166. pagination.total = res.pagination.total
  167. } catch (error) {
  168. Notification.error({
  169. title: '获取路径数据失败!',
  170. content: error.message || '请稍后再试'
  171. })
  172. } finally {
  173. loading.value = false
  174. }
  175. }
  176. // 分页 - 页码变化
  177. const handlePageChange = (page) => {
  178. pagination.current = page
  179. getPathList()
  180. }
  181. // 分页 - 每页条数变化
  182. const handlePageSizeChange = (size) => {
  183. pagination.pagesize = size
  184. pagination.current = 1 // 页大小变化后回到第一页
  185. getPathList()
  186. }
  187. onMounted(() => {
  188. getPathList()
  189. })
  190. function formatSecondsToMinSec(totalSeconds) {
  191. const minutes = Math.floor(totalSeconds / 60);
  192. const seconds = totalSeconds % 60;
  193. return `${minutes}分${seconds.toString().padStart(2, '0')}秒`;
  194. }
  195. </script>
  196. <style scoped>
  197. .table {
  198. margin-top: 15px;
  199. }
  200. </style>