tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<template>
  <div class="container" v-loading="loading">
    <div class="title" v-if="showTitle">
      <span>项目日志</span> <span class="back" @click="back"> <i class="iconfont icon-fanhui"></i> 返回 </span>
    </div>
 
    <el-timeline class="content">
      <el-timeline-item v-for="log in logs" :key="log.id" :timestamp="log.update_time" placement="top">
        <el-card>
          <h4>{{ log.module }}-{{ log.permission }}</h4>
          <p class="things">{{ log.message }}</p>
        </el-card>
      </el-timeline-item>
    </el-timeline>
 
    <div v-if="totalCount > count || totalCount === 0">
      <div v-if="logs?.length">
        <el-divider></el-divider>
        <div class="more" :class="{ nothing: finished }">
          <i v-if="more" class="iconfont icon-loading"></i>
          <div v-show="!more && !finished" @click="nextPage">
            <span>查看更多</span> <i class="iconfont icon-gengduo" style="font-size: 14px"></i>
          </div>
          <div v-if="finished">
            <span>{{ totalCount === 0 ? '暂无数据' : '没有更多数据了' }}</span>
          </div>
        </div>
      </div>
      <div class="nothing" v-else>暂无日志信息</div>
    </div>
  </div>
</template>
 
<script>
import logModel from 'lin/model/log'
 
import { ref, reactive, onMounted } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'
 
export default {
  props: {
    editId: {
      type: String,
      default: null,
    },
    showTitle: {
      type: Boolean,
      default: false,
    },
  },
  setup(props, context) {
    const form = ref(null)
    const loading = ref(false)
    const count = ref(10)
    const totalCount = ref(0)
    const logs = ref([])
    const finished = ref(false)
 
    const relationId = ref('')
 
    /**
     * Part 2
     * 根据调解筛选查询日志
     */
    const search = reactive({
      keyword: '',
      relationId: props.editId,
      searchUser: '',
      searchKeyword: '',
      searchDate: [],
      totalCount: 0,
      count: 10,
      page: 0,
    })
 
    const more = ref(false)
    const nextPage = async () => {
      more.value = true
      try {
        search.page += 1
        search.relationId = relationId.value
        const res = await logModel.relationLogs(search)
        const moreLogs = res.items
        logs.value = logs.value.concat(moreLogs)
        more.value = false
        count.value = logs.value.length
      } catch (error) {
        console.error('error', error)
        if (error.data.code === 10020) {
          finished.value = true
        }
        more.value = false
      }
    }
 
    onMounted(() => {
      loadDictDitems()
    })
 
    // 根据字典类型查询字典
    const loadDictDitems = async () => {
      if (props.editId) {
        relationId.value = props.editId
        searchPage()
      }
    }
 
    // 条件检索
    const searchPage = async () => {
      logs.value = []
      loading.value = true
      search.totalCount = 0
      totalCount.value = 0
      count.value = 0
      // finished.value = false
 
      const res = await logModel.relationLogs({
        page: 0, // 初始化
        keyword: search.searchKeyword,
        relationId: props.editId,
        start: search.searchDate[0],
        end: search.searchDate[1],
      })
      if (res) {
        const searchLogs = res.items
        search.totalCount = res.total
        logs.value = res.items
        totalCount.value = res.total
        count.value = logs.value.length
      } else {
        finished.value = true
      }
      // isSearch.value = true
      loading.value = false
    }
 
    // 重置表单
    const resetForm = () => {
      form.value.resetFields()
    }
 
    const back = () => {
      context.emit('editClose')
    }
 
    return {
      back,
      totalCount,
      count,
      logs,
      finished,
      more,
      nextPage,
      form,
      resetForm,
    }
  },
}
</script>
 
<style lang="scss" scoped>
.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;
    border-bottom: 1px solid #dae1ec;
 
    .back {
      float: right;
      margin-right: 40px;
      cursor: pointer;
    }
  }
 
  .content {
    padding: 10px;
  }
 
  .wrap {
    padding: 20px;
  }
 
  .submit {
    float: left;
  }
}
 
.things {
  font-size: 14px;
  color: #45526b;
  margin-bottom: 15px;
  margin-top: 5px;
}
 
.more {
  height: 40px;
  line-height: 40px;
  color: $theme;
  font-size: 14px;
  margin-left: 28px;
  cursor: pointer;
  &.nothing {
    cursor: text;
  }
 
  .icon-gengduo {
    display: inline;
    margin-left: 6px;
  }
 
  .icon-loading {
    &:before {
      display: inline-block;
      animation: spin 1s linear infinite;
    }
  }
}
 
.nothing {
  color: #45526b;
  font-size: 14px;
}
</style>