profileH5.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <div class="profileH5 bg-white" style="min-height: 100vh;">
  3. <div class="title">
  4. <div>我的</div>
  5. </div>
  6. <el-tabs v-model="query.type" @tab-click="tabChange" class="tabs w-full">
  7. <el-tab-pane label="公开" name="0"></el-tab-pane>
  8. <el-tab-pane label="非公开" name="1"></el-tab-pane>
  9. </el-tabs>
  10. <div class="lietRom flex-1 overflow-auto" v-infinite-scroll="load" infinite-scroll-disabled="disabled">
  11. <div class="list mt-4">
  12. <div v-for="(item, index) in characterList" :key="index"
  13. class="box2 relative rounded-lg overflow-hidden shadow-lg cursor-pointer" @click="clickShowPopup(item)">
  14. <div class="w-full overflow-hidden">
  15. <!-- <div v-if="item.type == 0" class="type2">审核中...</div> -->
  16. <img :src="baseApi + item.picture" class="w-full img" @error="$AIPohotoError" />
  17. </div>
  18. <div class="p-2">
  19. <h3 class="text-lg font-bold flex items-center">
  20. <div class="name" style="max-width: calc(100% - 18px);">{{ item.name }}</div>
  21. <i v-if="item.scene == 1" class="el-icon-video-camera-solid"></i>
  22. <i v-if="item.scene == 0" class="el-icon-user-solid"></i>
  23. </h3>
  24. <p class="prologue text-sm">
  25. {{ item.prologue }}
  26. </p>
  27. <div class="labels flex my-1 flex-wrap">
  28. <div v-for="(item2, index2) in item.labelArr" :key="index2"
  29. class="m-0.5 tag px-2 py-1 rounded flex items-center text-xs text-gray-500">
  30. <!-- <i class="fas fa-smile text-yellow-400 mr-2"></i> -->
  31. {{ item2 }}
  32. </div>
  33. </div>
  34. </div>
  35. <div class="absolute w-full bottom-0 flex items-center justify-between mt-3 px-2 pb-2">
  36. <div></div>
  37. <div class="flex items-center box1 text-red-500">
  38. <v-icon name="fire" scale="1" />
  39. <span class="ml-1">{{ item.hotCount || 0 }}</span>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. <p class="w-full py-4 text-gray-400 text-center" v-if="loading">加载中...</p>
  45. <p class="w-full py-4 text-gray-400 text-center" v-if="noMore">没有更多了</p>
  46. </div>
  47. <van-action-sheet v-model="showPopup">
  48. <div class="buttons mb-6">
  49. <van-cell v-if="selectObj.scene == 1" title="场景名称" :value="selectObj.name" />
  50. <van-cell title="查看资料" is-link @click="toDetail" />
  51. <van-cell title="删除" is-link @click="deleteData" />
  52. <div class="flex justify-around p-4">
  53. <van-button class="textButton w-28 rounded-full" size="small" @click="toChat">开始对话</van-button>
  54. <van-button class="buttonBg1 w-28 rounded-full" size="small" @click="toCreate">编辑</van-button>
  55. </div>
  56. </div>
  57. </van-action-sheet>
  58. </div>
  59. </template>
  60. <script>
  61. import { Dialog } from 'vant';
  62. import { queryCharacterAndSceneApi } from "@/api/profile.js"
  63. import {
  64. deleteSceneApi,
  65. deleteCharacterApi,
  66. setCharacterShowApi,
  67. editSceneApi
  68. } from "@/api/create.js"
  69. export default {
  70. data() {
  71. return {
  72. showPopup: false,
  73. selectObj: {},
  74. query: {
  75. pageSize: 10,
  76. pageNum: 0,
  77. type: 0
  78. },
  79. total: 0,
  80. loading: false,
  81. noMore: false,
  82. characterList: []
  83. }
  84. },
  85. computed: {
  86. disabled() {
  87. return this.loading || this.noMore
  88. }
  89. },
  90. mounted() {
  91. // this.initCharacterList()
  92. },
  93. methods: {
  94. tabChange() {
  95. this.initCharacterList()
  96. },
  97. load() {
  98. this.query.pageNum += 1
  99. this.getCharacterList()
  100. },
  101. initCharacterList() {
  102. this.characterList = []
  103. this.query.pageNum = 1
  104. this.getCharacterList()
  105. },
  106. getCharacterList(query) {
  107. this.loading = true
  108. let params = this.query
  109. if (query) {
  110. params = {
  111. ...params,
  112. ...query,
  113. }
  114. }
  115. queryCharacterAndSceneApi(params).then(res => {
  116. console.log(res, '角色列表');
  117. if (res.rows.length == 0) {
  118. this.noMore = true
  119. }
  120. this.characterList = [...this.characterList, ...res.rows]
  121. if ((this.query.pageNum * this.query.pageSize) >= res.total) {
  122. this.noMore = true
  123. }
  124. this.total = res.total
  125. this.loading = false
  126. })
  127. },
  128. clickShowPopup(item) {
  129. console.log(item, 'item');
  130. this.selectObj = item
  131. this.showPopup = true
  132. },
  133. toDetail() {
  134. let query = {}
  135. if (this.selectObj.scene == 0) {
  136. // 点击是角色
  137. query.id = this.selectObj.id
  138. } else if (this.selectObj.scene == 1) {
  139. // 点击是场景
  140. query.id = this.selectObj.characterId
  141. }
  142. this.$router.push({
  143. path: '/detailH5',
  144. query: query
  145. })
  146. },
  147. // 前往聊天页面
  148. toChat() {
  149. let query = {}
  150. if (this.selectObj.scene == 0) {
  151. // 点击是角色
  152. query.characterId = this.selectObj.id
  153. this.$router.push({
  154. path: '/chatH5',
  155. query: query
  156. })
  157. } else if (this.selectObj.scene == 1) {
  158. // 点击是场景
  159. query.characterId = this.selectObj.characterId
  160. query.sceneId = this.selectObj.id
  161. this.$router.push({
  162. path: '/chatH5',
  163. query: query
  164. })
  165. }
  166. },
  167. // 前往编辑页面
  168. toCreate() {
  169. if (this.selectObj.scene == 0) {
  170. // 点击是角色
  171. this.$router.push({
  172. path: '/create',
  173. query: {
  174. id: this.selectObj.id
  175. }
  176. })
  177. } else if (this.selectObj.scene == 1) {
  178. // 点击是场景
  179. this.$router.push({
  180. path: '/createScene',
  181. query: {
  182. sceneId: this.selectObj.id,
  183. characterId: this.selectObj.characterId
  184. }
  185. })
  186. }
  187. },
  188. // 删除
  189. deleteData() {
  190. if (this.selectObj.scene == 0) {
  191. // 删除角色
  192. Dialog.confirm({
  193. title: '提示',
  194. message: '此操作将永久删除该角色及其所有聊天记录, 是否继续?',
  195. confirmButtonText: '确定',
  196. cancelButtonText: '取消',
  197. type: 'warning'
  198. }).then(() => {
  199. deleteCharacterApi(this.selectObj.id).then(res => {
  200. this.$message({
  201. type: 'success',
  202. message: '删除成功!'
  203. });
  204. this.showPopup = false
  205. this.initCharacterList()
  206. })
  207. })
  208. } else if (this.selectObj.scene == 1) {
  209. // 删除场景
  210. this.$confirm('此操作将永久删除该场景及其所有聊天记录, 是否继续?', '提示', {
  211. confirmButtonText: '确定',
  212. cancelButtonText: '取消',
  213. type: 'warning'
  214. }).then(() => {
  215. deleteSceneApi(this.selectObj.id).then(res => {
  216. this.$message({
  217. type: 'success',
  218. message: '删除成功!'
  219. });
  220. this.showPopup = false
  221. this.initCharacterList()
  222. })
  223. })
  224. }
  225. },
  226. }
  227. }
  228. </script>
  229. <style lang="scss" scoped>
  230. .profileH5 {
  231. .title {
  232. height: 40px;
  233. line-height: 40px;
  234. font-size: 16px;
  235. // font-weight: 600;
  236. text-align: center;
  237. }
  238. .tabs {}
  239. }
  240. .lietRom {
  241. padding: 5px;
  242. padding-bottom: 60px;
  243. }
  244. .lietRom::-webkit-scrollbar {
  245. display: none;
  246. }
  247. .textButton {
  248. // color: #eee;
  249. margin-left: 5px;
  250. }
  251. .textButton:hover {
  252. color: #9333ea;
  253. }
  254. .labelButton {
  255. border: solid 1px #e6e6e6;
  256. background: var(--bg-color2);
  257. }
  258. .buttonBg1 {
  259. background: var(--bg-color1);
  260. color: #fff;
  261. }
  262. .topActive {
  263. background: var(--bg-color1);
  264. }
  265. .tag {
  266. background: var(--bg-color2);
  267. }
  268. .box1 {
  269. border: 1px solid #ffffff4d;
  270. height: 30px;
  271. padding: 0 10px;
  272. border-radius: 18px;
  273. // width: 68px;
  274. font-size: 14px;
  275. }
  276. .box2 {
  277. background: #ffffff0f;
  278. border: 1px solid #ffffff2e;
  279. height: 325px;
  280. .name {
  281. overflow: hidden;
  282. text-overflow: ellipsis;
  283. -webkit-line-clamp: 1;
  284. display: -webkit-box;
  285. -webkit-box-orient: vertical;
  286. }
  287. }
  288. .box2:hover {
  289. border: solid 1px var(--bg-color1);
  290. }
  291. .img {
  292. height: 200px;
  293. object-fit: cover;
  294. object-position: top;
  295. transition: transform .2s
  296. }
  297. .img:hover {
  298. transform: scale(1.1);
  299. }
  300. .labels {
  301. max-height: 56px;
  302. overflow-y: auto;
  303. }
  304. .prologue {
  305. overflow: hidden;
  306. text-overflow: ellipsis;
  307. -webkit-line-clamp: 2;
  308. display: -webkit-box;
  309. -webkit-box-orient: vertical;
  310. }
  311. </style>
  312. <style scoped>
  313. .list {
  314. display: grid;
  315. grid-template-columns: 1fr 1fr;
  316. /* grid-auto-rows: minmax(280px, 280px); */
  317. grid-gap: 10px;
  318. }
  319. .tabs>>>.el-tabs__nav {
  320. width: 100%;
  321. }
  322. .tabs>>>.el-tabs__item {
  323. width: 50%;
  324. padding: 0;
  325. text-align: center;
  326. }
  327. .type2 {
  328. padding: 2px 4px;
  329. background: rgba(0, 0, 0, 0.4);
  330. color: #fff;
  331. position: absolute;
  332. top: 0;
  333. right: 0;
  334. font-size: 12px;
  335. }
  336. </style>