<template>
  <div>
    <pre class="code language-php line-numbers" v-html="html"></pre>
    <el-button ref="btnCopy" type="info" style="position: absolute; top: 20px; right: 10px;">复制</el-button>
  </div>
</template>

<script>

import Prism from 'prismjs';
import 'prismjs/components/prism-markup-templating';
import 'prismjs/components/prism-php';
import FpCodeMixin from './FpCodeMixin';

export default {
  name: "FpCodePhp",
  mixins: [FpCodeMixin],
  computed: {
    html() {
      return Prism.highlight(this.code(), Prism.languages.php, 'php');
    }
  },
  methods: {
    code() {
      let c1 = this.json().replaceAll('":', '" =>')
      c1 = '[' + c1.substring(1, c1.length - 1) + ']';

      let c = `include_once "vendor/autoload.php";

# 如需进一步了解，请参考开发文档 https://cloud.fastposter.net/doc/sdk/

# 1.创建海报客户端对象
$client = new Fastposter\\Client("${this.token}", "${this.apiUrl}");

# 2.准备海报参数（从实际业务系统中获取）
$params = ${c1};

# 3.生成海报并保存(提供图片流、二进制、base64等多种方式)
$client->buildPoster("${this.posterId || '未生成'}", $params)->save("demo.png");`
      return c
    }
  }
}
</script>

<style scoped>

.code {
  text-align: left;
  overflow: auto;
  user-select: text;
  cursor: text;
  height: 500px;
  font-size: 13px;
}

</style>