<script>
import {mapGetters, mapState} from "vuex";
import ClipboardJS from 'clipboard';

export default {
  name: "FpCodeMixin",
  mounted() {
    let that = this;
    let clipboard = new ClipboardJS(this.$refs['btnCopy'].$el, {
      text() {
        return that.code();
      }
    });
    clipboard.on('success', () => {
      this.$message({
          message: '复制成功',
          type: 'success',
          duration: 1000
        });
    });
  },
  computed: {
    ...mapState({
      items: state => state.poster.p.items,
      posterId: state => state.poster.p.uuid,
    }),
    ...mapGetters({
      'token': 'editor/token',
      'apiUrl': 'editor/apiUrl',
    }),
  },
  methods: {
    code() {
      return '';
    },
    json() {
      let c1 = {}
      this.items.filter(e => e.vd).forEach(e => {
        c1[e.vd] = e.v
      })
      c1 = JSON.stringify(c1, '', '  ')
      return c1
    },
  }
}
</script>

<style scoped lang="less">

@import "~prismjs/themes/prism-tomorrow.css";

</style>