index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <!-- components/agent-ui/collapsibleCard/index.wxml -->
  3. <view class="collapse" :style="collapsedStatus && showBgColor ? 'background-color: #f5f5f5;' : ''">
  4. <view class="collapse-header" @tap="changeCollapsedStatus">
  5. <slot name="title"></slot>
  6. <image
  7. src="/static/components/agent-ui/imgs/arrow.svg"
  8. mode="aspectFill"
  9. :style="'width: 16px;height: 16px;transform: rotate(' + (collapsedStatus ? 0 : 180) + 'deg);'"
  10. />
  11. </view>
  12. <block v-if="collapsedStatus">
  13. <slot name="content"></slot>
  14. </block>
  15. </view>
  16. </template>
  17. <script>
  18. // components/agent-ui/collapsibleCard/index.js
  19. export default {
  20. data() {
  21. return {
  22. collapsedStatus: false
  23. };
  24. },
  25. /**
  26. * 组件的属性列表
  27. */
  28. props: {
  29. initStatus: {
  30. type: Boolean,
  31. default: false
  32. },
  33. showBgColor: {
  34. type: Boolean,
  35. default: false
  36. }
  37. },
  38. mounted() {
  39. // 处理小程序 attached 生命周期
  40. this.attached();
  41. },
  42. /**
  43. * 组件的方法列表
  44. */
  45. methods: {
  46. attached() {
  47. this.setData({
  48. collapsedStatus: this.initStatus
  49. });
  50. },
  51. changeCollapsedStatus: function () {
  52. this.setData({
  53. collapsedStatus: !this.collapsedStatus
  54. });
  55. }
  56. },
  57. options: {
  58. multipleSlots: true
  59. },
  60. created: function () {}
  61. };
  62. </script>
  63. <style>
  64. /* components/agent-ui/collapsibleCard/index.wxss */
  65. .collapse {
  66. border-radius: 8px;
  67. margin-bottom: 12px;
  68. }
  69. .collapse-header {
  70. display: inline-flex;
  71. align-items: center;
  72. gap: 8px;
  73. background-color: #f5f5f5;
  74. justify-content: space-between;
  75. padding: 18rpx 26rpx;
  76. border-radius: 8px;
  77. }
  78. </style>