advertisement.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="model-item-container">
  3. <br />
  4. <el-form label-width="100px" :model="form" label-position="top">
  5. <el-form-item label="请输入产品名称/品类/主题">
  6. <el-input
  7. v-model="form.title"
  8. type="textarea"
  9. :rows="2"
  10. maxlength="100"
  11. show-word-limit
  12. placeholder="如:iPhone 13,保温杯,保护野生动物"
  13. />
  14. </el-form-item>
  15. </el-form>
  16. <el-form>
  17. <el-form-item label="文章长度">
  18. <div style="text-align: right; width: 100%">
  19. <el-button plain :class="{ act: form.long === 'short' }">
  20. </el-button>
  21. <el-button plain :class="{ act: form.long === 'default' }">
  22. </el-button>
  23. <el-button plain :class="{ act: form.long === 'long' }">
  24. </el-button>
  25. </div>
  26. </el-form-item>
  27. </el-form>
  28. <div class="btn_group">
  29. <el-button
  30. type="primary"
  31. style="width: 100%"
  32. @click="createContent"
  33. :loading="load"
  34. >生成内容</el-button
  35. >
  36. <div class="bottom-content-safe-tip">
  37. <img :src="image_base64.tanhao" class="content-safe-tip-icon" />
  38. <div class="content-safe-tip-text">
  39. 声明:内容为概率模型生成,可能会产生不正确的信息,不代表我司的观点和立场
  40. </div>
  41. </div>
  42. </div>
  43. <template v-if="form.list.length">
  44. <el-pagination
  45. :page-size="form.count"
  46. layout="prev, pager, next"
  47. :total="form.list.length"
  48. :current-page="form.page"
  49. />
  50. <div class="item" v-for="(item, i) in form.list[form.page - 1]" :key="i">
  51. <div class="content" v-text="item.text"></div>
  52. <div class="btn_div">
  53. <el-tooltip
  54. class="box-item"
  55. effect="dark"
  56. content="左侧导入"
  57. placement="top"
  58. >
  59. <el-icon
  60. @click="() => inputText(item.text)"
  61. style="
  62. left: 50;
  63. top: 50%;
  64. transform: translate(-50%, -50%);
  65. cursor: pointer;
  66. "
  67. color="#cacaca"
  68. ><DArrowLeft
  69. /></el-icon>
  70. </el-tooltip>
  71. </div>
  72. <div class="btn_div">
  73. <el-tooltip
  74. class="box-item"
  75. effect="dark"
  76. content="复制"
  77. placement="top"
  78. >
  79. <el-icon
  80. style="
  81. left: 50;
  82. top: 50%;
  83. transform: translate(-50%, -50%);
  84. cursor: pointer;
  85. "
  86. color="#cacaca"
  87. ><CopyDocument
  88. /></el-icon>
  89. </el-tooltip>
  90. </div>
  91. </div>
  92. <div style="text-align: center">
  93. <el-button @click="refresh" type="primary" :icon="Refresh" link
  94. >换一批</el-button
  95. >
  96. </div>
  97. </template>
  98. </div>
  99. </template>
  100. <script setup>
  101. import { ref, defineEmits } from 'vue';
  102. import { image_base64 } from './data.js';
  103. import { advertisement, generate_pc_get } from '@/api/aleditor.js';
  104. import { Refresh } from '@element-plus/icons-vue';
  105. const emits = defineEmits(['closeType', 'setHtml', 'getImage']);
  106. const form = ref({
  107. title: '',
  108. long: 'short',
  109. list: [],
  110. page: 1,
  111. count: 5,
  112. });
  113. const load = ref(false);
  114. const createContent = () => {
  115. if (!form.value.title) return;
  116. const p = {
  117. count: form.value.count,
  118. data: { title: form.value.title, prev: '', next: '' },
  119. generateType: 1,
  120. length: form.value.long,
  121. noblock: true,
  122. query_type: 'slogan',
  123. };
  124. load.value = true;
  125. form.value.page = 1;
  126. advertisement({
  127. data: p,
  128. noload: true,
  129. })
  130. .then(r => {
  131. if (r.errCode !== 0) return (load.value = false);
  132. p.req = { doc_id: r.data.doc_id };
  133. get(p);
  134. })
  135. .catch(() => {
  136. load.value = false;
  137. });
  138. };
  139. const get = p => {
  140. generate_pc_get({
  141. data: p,
  142. noload: true,
  143. })
  144. .then(res => {
  145. load.value = false;
  146. if (res.errCode !== 0 && res.data.status === 'RUNNING') {
  147. let t = setTimeout(() => {
  148. get(p);
  149. clearTimeout(t);
  150. }, 200);
  151. return;
  152. }
  153. const list = res.data.result.content;
  154. const l = [];
  155. for (let i = 0; i < list.length; i++) {
  156. const v = list[i];
  157. l.push({
  158. text: v,
  159. });
  160. }
  161. form.value.list.push(l);
  162. })
  163. .catch(() => {
  164. load.value = false;
  165. });
  166. };
  167. const inputText = text => {
  168. emits('setHtml', text);
  169. };
  170. const refresh = () => {
  171. if (!form.value.title) return;
  172. const p = {
  173. count: form.value.count,
  174. data: { title: form.value.title, prev: '', next: '' },
  175. generateType: 1,
  176. length: form.value.long,
  177. noblock: true,
  178. query_type: 'slogan',
  179. };
  180. load.value = true;
  181. advertisement({
  182. data: p,
  183. noload: true,
  184. })
  185. .then(r => {
  186. if (r.errCode !== 0) return (load.value = false);
  187. p.req = { doc_id: r.data.doc_id };
  188. get(p);
  189. })
  190. .catch(() => {
  191. load.value = false;
  192. });
  193. };
  194. </script>
  195. <style scoped>
  196. .model-item-container {
  197. text-align: center;
  198. -webkit-box-flex: 1;
  199. -ms-flex: 1;
  200. flex: 1;
  201. display: -webkit-box;
  202. display: -ms-flexbox;
  203. display: flex;
  204. -webkit-box-orient: vertical;
  205. -webkit-box-direction: normal;
  206. -ms-flex-direction: column;
  207. flex-direction: column;
  208. min-height: 0;
  209. width: 95%;
  210. height: 100%;
  211. }
  212. .act {
  213. color: var(--el-button-hover-text-color);
  214. border-color: var(--el-button-hover-border-color);
  215. background-color: var(--el-button-hover-bg-color);
  216. outline: 0;
  217. }
  218. .btn_group {
  219. padding-right: 1em;
  220. }
  221. .bottom-content-safe-tip {
  222. display: -webkit-box;
  223. display: -ms-flexbox;
  224. display: flex;
  225. padding: 15px 0;
  226. -webkit-box-pack: center;
  227. -ms-flex-pack: center;
  228. justify-content: center;
  229. width: 100%;
  230. zoom: 0.83;
  231. }
  232. .bottom-content-safe-tip .content-safe-tip-icon {
  233. width: 15px;
  234. height: 15px;
  235. margin-right: 10px;
  236. }
  237. .bottom-content-safe-tip .content-safe-tip-text {
  238. font-size: 12px;
  239. line-height: 15px;
  240. color: #cacaca;
  241. }
  242. .item {
  243. width: 100%;
  244. min-height: 45px;
  245. -webkit-box-sizing: border-box;
  246. box-sizing: border-box;
  247. margin-bottom: 20px;
  248. text-align: left;
  249. position: relative;
  250. padding: 10px 10px 10px 0;
  251. display: flex;
  252. -webkit-box-align: center;
  253. -ms-flex-align: center;
  254. align-items: center;
  255. border-bottom: 1px solid #eee;
  256. }
  257. .content {
  258. -webkit-box-flex: 1;
  259. -ms-flex: 1;
  260. flex: 1;
  261. outline: none;
  262. line-height: 28px;
  263. text-align: justify;
  264. overflow-y: auto;
  265. }
  266. .hover_class,
  267. .item:hover {
  268. background-color: #f5f5f5;
  269. border-bottom: 1px solid #f8f8f8;
  270. }
  271. .btn_div {
  272. height: 30px;
  273. width: 30px;
  274. position: relative;
  275. }
  276. </style>