CmtBottom.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view class="nut-comment-bottom">
  3. <view @click="handleClick" class="nut-comment-bottom__lable">
  4. <span v-if="type != 'complex'">{{ info.size }}</span></view
  5. >
  6. <view class="nut-comment-bottom__cpx">
  7. <template v-for="(name, i) in mergeOp" :key="i">
  8. <view :class="['nut-comment-bottom__cpx-item', `nut-comment-bottom__cpx-item--${name}`]" @click="operate(name)">
  9. <template v-if="name != 'more'">
  10. <span>{{ info[name] }}</span>
  11. <nut-icon :name="name == 'like' ? 'fabulous' : 'comment'"></nut-icon>
  12. </template>
  13. <template v-if="name == 'more'">
  14. <nut-icon name="more-x"></nut-icon>
  15. <view class="nut-comment-bottom__cpx-item-popover" v-if="showPopver" @click="operate('popover')">{{
  16. translate('complaintsText')
  17. }}</view>
  18. </template>
  19. </view>
  20. </template>
  21. </view>
  22. </view>
  23. </template>
  24. <script lang="ts">
  25. import { ref, watch, onMounted, PropType } from 'vue';
  26. import { createComponent } from '@/packages/utils/create';
  27. const { componentName, create, translate } = createComponent('comment-bottom');
  28. export default create({
  29. props: {
  30. type: {
  31. type: String,
  32. default: 'base' // simple,base,complex
  33. },
  34. info: {
  35. type: Object,
  36. default: () => {}
  37. },
  38. operation: {
  39. type: Array as PropType<string[]>,
  40. default: ['replay', 'like', 'more']
  41. }
  42. },
  43. components: {},
  44. emits: ['clickOperate', 'handleClick'],
  45. setup(props, { emit }) {
  46. const showPopver = ref(false);
  47. const mergeOp = ref([]);
  48. onMounted(() => {
  49. const deOp = ['replay', 'like', 'more'];
  50. if (props.operation) {
  51. props.operation.forEach((name: string) => {
  52. if (deOp.includes(name)) {
  53. (mergeOp.value as any).push(name);
  54. }
  55. });
  56. }
  57. });
  58. const operate = (type: string) => {
  59. if (type == 'more') {
  60. showPopver.value = !showPopver.value;
  61. }
  62. emit('clickOperate', type);
  63. };
  64. const handleClick = () => {
  65. emit('handleClick');
  66. };
  67. return { showPopver, operate, mergeOp, handleClick, translate };
  68. }
  69. });
  70. </script>