qiyunfeng-create
2 天以前 5f00696dfb25bc90034448ceb634ed1ef256681a
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<template>
  <div class="classManagePage-box">
    <div class="classManagePage-nav">
      <el-breadcrumb :separator-icon="ArrowRight">
        <el-breadcrumb-item>我的班级</el-breadcrumb-item>
        <el-breadcrumb-item>{{ classInfo?.name }}</el-breadcrumb-item>
        <el-breadcrumb-item>话题</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="classManagePage-content">
      <div class="headerBox">
        <div class="searchBox">
          <el-input
            v-model="searchKey"
            @clear="searchData()"
            @keydown.enter="searchData()"
            clearable
            placeholder="搜索话题名称"
          >
            <template #append>
              <el-button type="primary" class="searchBtn" @click="searchData()" :icon="Search" />
            </template>
          </el-input>
        </div>
        <el-button @click="openTalk()" v-if="userInfo?.role == 'Teacher'" type="primary" round>
          新建 <el-icon><Plus /></el-icon>
        </el-button>
      </div>
      <div class="listBox">
        <el-table
          :header-cell-style="{ background: '#eee' }"
          :data="dataList"
          border
          v-loading="isLoading"
          style="width: 100%"
        >
          <el-table-column prop="index" label="序号" width="70" />
          <el-table-column label="话题名称" width="500">
            <template #default="scope">
              <span style="color: #ff6c00" v-if="scope.row.name">{{ scope.row.name }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="createDate" label="发起日期" />
          <el-table-column label="发起人">
            <template #default="scope">
              <span v-if="scope.row.publicText">{{ scope.row.publicText.publisher }}</span>
            </template>
          </el-table-column>
          <el-table-column label="发起人角色">
            <template #default="scope">
              <span v-if="scope.row.publicText?.publishRole == 'Teacher'">助教</span>
              <span v-else>学生</span>
            </template>
          </el-table-column>
          <el-table-column prop="updateDate" label="发起人最后回复日期" />
          <el-table-column label="操作" width="180px">
            <template #default="scope">
              <el-button
                link
                type="primary"
                v-if="scope.row.state == 'Normal'"
                @click="toDetail(scope.row)"
                >详情</el-button
              >
              <el-button
                link
                type="success"
                v-if="scope.row.state != 'Normal'"
                @click="pubTalk(scope.row)"
                >发布</el-button
              >
              <el-button
                link
                type="danger"
                v-if="userInfo.role == 'Teacher'"
                @click="delMessageItem(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          style="float: right"
          v-model:current-page="pages.page"
          :page-size="pages.pageSize"
          layout="total, prev, pager, next"
          :total="pages.count"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
      <el-dialog v-model="dialogVisible" title="新建话题" width="800">
        <div class="talkWall">
          <div class="talKBox">
            <span>话题标题:</span>
            <el-input v-model="talkTitle" style="width: 440px" placeholder="请输入标题" />
          </div>
          <div class="talKBox">
            <span>话题内容:</span>
            <el-input
              style="flex: 1"
              v-model="talkContent"
              :autosize="{ minRows: 10, maxRows: 15 }"
              type="textarea"
              placeholder="请输入内容"
            />
          </div>
        </div>
        <template #footer>
          <div class="dialog-footer">
            <el-button @click="dialogVisible = false"> 取消 </el-button>
            <el-button type="primary" @click="createMessage()"> 确认 </el-button>
          </div>
        </template>
      </el-dialog>
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { reactive, ref, onMounted, inject, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { Search, ArrowRight } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import moment from 'moment'
const route: any = useRoute()
const router = useRouter()
const MG: any = inject('MG')
const config: any = inject('config')
const classInfo = JSON.parse(route.query.classInfo)
const userInfo = ref()
 
const searchKey = ref('')
const talkTitle = ref('')
const talkContent = ref('')
const dialogVisible = ref(false)
const talkTopicInfo = ref()
const dataList = ref([])
const isLoading = ref(false)
let pages = reactive({
  page: 1,
  pageSize: 10,
  count: 0,
  loading: false
})
 
onMounted(() => {
  const userCache: any = localStorage.getItem(config.userInfoKey)
  if (userCache) {
    userInfo.value = JSON.parse(userCache)
  }
  getTopicInfo()
})
 
const handleSizeChange = (val: number) => {
  pages.pageSize = val
  getMessage()
}
 
const handleCurrentChange = (val: number) => {
  pages.page = val
  getMessage()
}
 
const searchData = () => {
  pages.page = 1
  pages.pageSize = 10
  getMessage()
}
 
// 获取话题topic
const getTopicInfo = () => {
  const pramas = {
    classId: classInfo.id,
    refCodes: [config.refCodes.talk]
  }
  MG.edu.getClassTopic(pramas).then((res: any) => {
    const list = res
    talkTopicInfo.value = list.find((item: any) => item.refCode == config.refCodes.talk)
    if (talkTopicInfo.value.id) {
      getMessage()
    }
  })
}
 
//  新建话题
const createMessage = () => {
  if (talkTitle.value == '') {
    ElMessage({
      message: '请填写标题',
      type: 'warning'
    })
    return false
  }
  if (talkContent.value == '') {
    ElMessage({
      message: '请填写内容',
      type: 'warning'
    })
    return false
  }
  newTalkMessage()
}
 
// 话题详情
const toDetail = (item: any) => {
  const obj = classInfo
  obj.MessageName = item.name
  router.push({
    path: '/talkDetail',
    query: {
      classInfo: JSON.stringify(obj)
    }
  })
}
 
const newTalkMessage = () => {
  const userCache: any = localStorage.getItem(config.userInfoKey)
  const userInfo = JSON.parse(userCache)
  const textObj = {
    content: talkContent.value,
    publisher: userInfo?.name ?? '',
    publishRole: userInfo?.role ?? '',
    icon: userInfo.icon ?? ''
  }
  const data = {
    description: '',
    icon: '',
    state: 'Normal',
    topicIdOrRefCode: String(talkTopicInfo.value.id),
    name: talkTitle.value,
    content: JSON.stringify(textObj),
    type: 'Normal',
    cmsTypeRefCode: '',
    newDataListRequest: []
  }
  MG.ugc.newTopicMessage(data).then((res: any) => {
    if (res) {
      dialogVisible.value = false
      getMessage()
    }
  })
}
 
// 获取班级话题
const getMessage = () => {
  isLoading.value = true
  const data = {
    start: (pages.page - 1) * pages.pageSize,
    size: pages.pageSize,
    appRefCode: config.appRefCode,
    topicIdOrRefCode: String(talkTopicInfo.value.id),
    searchList: searchKey.value
      ? [
          {
            keywords: searchKey.value,
            field: 'Name',
            compareType: 'Contains'
          }
        ]
      : []
  }
  MG.ugc.getTopicMessageList(data).then((res: any) => {
    const list = res.datas
    pages.count = res.totalSize
    isLoading.value = false
    dataList.value = list.map((item: any, i: number) => {
      const str = item.content.indexOf('publisher')
      if (str > -1) {
        item.publicText = JSON.parse(item.content)
      }
      return {
        ...item,
        index: i + 1,
        createDate: moment(item.createDate).format('YYYY-MM-DD HH:mm:ss'),
        updateDate: moment(item.updateDate).format('YYYY-MM-DD HH:mm:ss')
      }
    })
  })
}
 
// 删除话题
const delMessageItem = (item: any) => {
  const data = {
    messageIds: [item.id]
  }
  MG.ugc
    .delTopicMessage(data)
    .then((res: any) => {
      if (res) {
        ElMessage.success('已删除')
        getTopicInfo()
      }
    })
    .catch((err: any) => {
      ElMessage.error('删除失败,请稍后再试')
      console.log(err)
    })
}
 
// 审核话题
const pubTalk = (item: any) => {
  const data = {
    id: item.id,
    name: item.name,
    description: item.description,
    icon: item.icon,
    type: item.type,
    state: 'Normal',
    content: JSON.stringify(item.publicText),
    newDataRequests: [],
    updateDataRequests: []
  }
  MG.ugc
    .updateTopicMessage(data)
    .then((res: any) => {
      if (res) {
        ElMessage({
          type: 'success',
          message: '已发布'
        })
        getMessage()
      }
    })
    .catch((err: any) => {
      console.log(err, '审核话题')
    })
}
 
const openTalk = () => {
  dialogVisible.value = true
}
</script>
 
<style lang="less" scoped>
.classManagePage-box {
  padding: 20px;
  .classManagePage-nav {
    padding-bottom: 20px;
    border-bottom: 1px solid #e6e8ed;
  }
  .classManagePage-content {
    .headerBox {
      padding: 20px 0;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .searchBox {
        width: 300px;
        float: left;
        .searchBtn {
          background-color: var(--el-color-primary);
          color: #fff;
          border-top-left-radius: 0;
          border-bottom-left-radius: 0;
        }
      }
    }
  }
}
.headerCellClass {
  background-color: red !important;
}
 
.talkWall {
  width: 100%;
  height: auto;
  .talKBox {
    display: flex;
    align-items: baseline;
    margin-bottom: 20px;
  }
}
</style>