prompt.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view>
  3. <cu-custom bgColor="bg-cyan" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content">提示词</block>
  6. </cu-custom>
  7. <view class="cu-bar bg-white margin-top-xs">
  8. <view class="action sub-title">
  9. <text class="text-xl text-bold text-cyan text-shadow">收藏</text>
  10. <text class="text-ABC text-cyan">Favorite</text>
  11. </view>
  12. </view>
  13. <PromptList :promptList="promptFavor" @toggle-favor="getPromptFavor"></PromptList>
  14. <view class="cu-bar bg-white margin-top-xs">
  15. <view class="action sub-title">
  16. <text class="text-xl text-bold text-cyan text-shadow">常用</text>
  17. <text class="text-ABC text-cyan">Common</text>
  18. </view>
  19. <view class="action">
  20. <text class="text-cyan" @tap="$squni.navigateTo('/pages/main/prompt/prompt-list')">查看更多></text>
  21. </view>
  22. </view>
  23. <PromptList :promptList="promptCommon" @toggle-favor="getPromptFavor"></PromptList>
  24. </view>
  25. </template>
  26. <script>
  27. import PromptList from '@/components/prompt-list/prompt-list.vue'
  28. import { findPromptListApi } from '@/api/chat.js'
  29. export default {
  30. components: { PromptList },
  31. data() {
  32. return {
  33. promptFavor: [],
  34. promptCommon: []
  35. }
  36. },
  37. created() {
  38. findPromptListApi({ commonOpt: 1 }).then(({ status, data }) => {
  39. if (status === 'success') {
  40. this.promptCommon = data
  41. }
  42. })
  43. },
  44. onShow() {
  45. this.getPromptFavor()
  46. },
  47. methods: {
  48. getPromptFavor () {
  49. if (this.$store.getters.favorPromptList.length <= 0) {
  50. return
  51. }
  52. findPromptListApi({ ids: this.$store.getters.favorPromptList }).then(({ status, data }) => {
  53. if (status === 'success') {
  54. let map = {}
  55. data.forEach(x => map[x.id] = x)
  56. let list = []
  57. for(let id of this.$store.getters.favorPromptList) {
  58. list.push(map[id])
  59. }
  60. this.promptFavor = list
  61. }
  62. })
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss">
  68. </style>