RoleList.vue 4.0 KB

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