RoleList.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div class="card-list" ref="tabsRef" @scroll="handleTabsScroll">
  3. <div class="card-item" v-for="role in roleList" :key="role.id">
  4. <el-card class="card" body-class="card-body">
  5. <!-- 更多 -->
  6. <div class="more-container">
  7. <el-dropdown @command="handleMoreClick">
  8. <span class="el-dropdown-link">
  9. <el-button type="text" >
  10. <el-icon><More /></el-icon>
  11. </el-button>
  12. </span>
  13. <template #dropdown>
  14. <el-dropdown-menu>
  15. <el-dropdown-item :command="['edit', role]" >
  16. <el-icon><EditPen /></el-icon>编辑
  17. </el-dropdown-item>
  18. <el-dropdown-item :command="['delete', role]" style="color: red;" >
  19. <el-icon><Delete /></el-icon>
  20. <span>删除</span>
  21. </el-dropdown-item>
  22. </el-dropdown-menu>
  23. </template>
  24. </el-dropdown>
  25. </div>
  26. <!-- 头像 -->
  27. <div>
  28. <img class="avatar" :src="role.avatar"/>
  29. </div>
  30. <div class="right-container">
  31. <div class="content-container">
  32. <div class="title">{{ role.name }}</div>
  33. <div class="description">{{ role.description }}</div>
  34. </div>
  35. <div class="btn-container">
  36. <el-button type="primary" size="small" @click="handleUseClick(role)">使用</el-button>
  37. </div>
  38. </div>
  39. </el-card>
  40. </div>
  41. </div>
  42. </template>
  43. <script setup lang="ts">
  44. import {ChatRoleVO} from '@/api/ai/model/chatRole'
  45. import {PropType, ref} from "vue";
  46. import {Delete, EditPen, More} from "@element-plus/icons-vue";
  47. const tabsRef = ref<any>() // tabs ref
  48. // 定义属性
  49. const props = defineProps({
  50. loading: {
  51. type: Boolean,
  52. required: true
  53. },
  54. roleList: {
  55. type: Array as PropType<ChatRoleVO[]>,
  56. required: true
  57. }
  58. })
  59. // 定义钩子
  60. const emits = defineEmits(['onDelete', 'onEdit', 'onUse', 'onPage'])
  61. // more 点击
  62. const handleMoreClick = async (data) => {
  63. const type = data[0]
  64. const role = data[1]
  65. if (type === 'delete') {
  66. emits('onDelete', role)
  67. } else {
  68. emits('onEdit', role)
  69. }
  70. }
  71. // 使用
  72. const handleUseClick = (role) => {
  73. emits('onUse', role)
  74. }
  75. const handleTabsScroll = async () => {
  76. if (tabsRef.value) {
  77. const { scrollTop, scrollHeight, clientHeight } = tabsRef.value;
  78. console.log('scrollTop', scrollTop)
  79. if (scrollTop + clientHeight >= scrollHeight - 20 && !props.loading) {
  80. console.log('分页')
  81. // page.value++;
  82. // fetchData(page.value);
  83. await emits('onPage')
  84. }
  85. }
  86. }
  87. onMounted(() => {
  88. console.log('props', props.roleList)
  89. })
  90. </script>
  91. <style lang="scss">
  92. // 重写 card 组件 body 样式
  93. .card-body {
  94. max-width: 240px;
  95. width: 240px;
  96. padding: 15px;
  97. display: flex;
  98. flex-direction: row;
  99. justify-content: flex-start;
  100. position: relative;
  101. }
  102. </style>
  103. <style scoped lang="scss">
  104. // 卡片列表
  105. .card-list {
  106. display: flex;
  107. flex-direction: row;
  108. flex-wrap: wrap;
  109. position: relative;
  110. height: 100%;
  111. overflow: auto;
  112. padding: 0px 25px;
  113. padding-bottom: 140px;
  114. align-items: start;
  115. align-content: flex-start;
  116. justify-content: start;
  117. .card {
  118. display: inline-block;
  119. margin-right: 20px;
  120. border-radius: 10px;
  121. margin-bottom: 30px;
  122. position: relative;
  123. .more-container {
  124. position: absolute;
  125. top: 0;
  126. right: 12px;
  127. }
  128. .avatar {
  129. width: 40px;
  130. height: 40px;
  131. border-radius: 10px;
  132. overflow: hidden;
  133. }
  134. .right-container {
  135. margin-left: 10px;
  136. width: 100%;
  137. //height: 100px;
  138. .content-container {
  139. height: 85px;
  140. .title {
  141. font-size: 18px;
  142. font-weight: bold;
  143. color: #3e3e3e;
  144. }
  145. .description {
  146. margin-top: 10px;
  147. font-size: 14px;
  148. color: #6a6a6a;
  149. }
  150. }
  151. .btn-container {
  152. display: flex;
  153. flex-direction: row-reverse;
  154. margin-top: 2px;
  155. }
  156. }
  157. }
  158. }
  159. </style>