CheckPic.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="check-article">
  3. <div class="main">
  4. <div v-for="(item, index) in data.detail" :key="index + 'paragraph'" class="paragraph">
  5. <label>段 {{ index + 1 }}</label>
  6. <template v-if="data.type === 'article'">
  7. <el-upload
  8. :key="index"
  9. action="no"
  10. accept="image/*,video/*"
  11. :file-list="item.sourceList"
  12. :http-request="handleImage"
  13. :before-upload="handleBeforeImage"
  14. :on-exceed="handleExceed"
  15. :on-remove="handleRemove"
  16. :limit="1"
  17. class="upload-resource"
  18. @click.native="handleItem(index)"
  19. >
  20. <div class="remark-box"><i class="el-icon-upload"></i>上传图片/视频</div>
  21. </el-upload>
  22. <div class="set-para">
  23. <span>图片/视频位置:</span>
  24. <el-radio-group v-model="item.sourcePosition">
  25. <el-radio label="before">段落前</el-radio>
  26. <el-radio label="after">段落后</el-radio>
  27. </el-radio-group>
  28. </div>
  29. <div class="set-para">
  30. <span class="adult-book-lable">图片宽度:</span>
  31. <el-input
  32. v-model="item.widthNumber"
  33. class="adult-book-input"
  34. placeholder="请输入宽度值"
  35. maxlength="200"
  36. style="width: 150px"
  37. @blur="onBlur(item, 'widthNumber')"
  38. />
  39. <span class="adult-book-lable">图片高度:</span>
  40. <el-input
  41. v-model="item.heightNumber"
  42. class="adult-book-input"
  43. placeholder="请输入高度值"
  44. maxlength="200"
  45. style="width: 150px"
  46. @blur="onBlur(item, 'heightNumber')"
  47. />
  48. </div>
  49. </template>
  50. <div v-for="(items, indexs) in item.wordsList" :key="indexs + 'words'" class="sentence-box">
  51. <div class="sentence">
  52. <b>{{ indexs + 1 }}.</b>
  53. <div class="sentence">
  54. <span v-for="(itemss, indexss) in items" :key="indexss" class="sentence-item" @click="showPic(itemss)">
  55. {{ itemss.chs }}
  56. <img
  57. v-if="itemss.img && itemss.img.length > 0"
  58. style="height: 16px"
  59. :src="itemss.img[0].file_url_open"
  60. />
  61. <div :contenteditable="true" class="sentence-pic"></div>
  62. </span>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. <el-dialog title="上传图片" :visible.sync="remarkVisible" width="50%" :close-on-click-modal="false" append-to-body>
  69. <template v-if="itemActive">
  70. <el-upload
  71. action="no"
  72. accept="image/*,video/*"
  73. :file-list="itemActive.img"
  74. :http-request="handleImages"
  75. :before-upload="handleBeforeImages"
  76. :on-exceed="handleExceeds"
  77. :on-remove="handleRemoves"
  78. :limit="1"
  79. class="upload-resource"
  80. >
  81. <div class="remark-box"><i class="el-icon-upload"></i>上传图片</div>
  82. </el-upload>
  83. </template>
  84. <span slot="footer" class="dialog-footer">
  85. <!-- <el-button @click="remarkVisible = false">取 消</el-button> -->
  86. <el-button type="primary" @click="remarkVisible = false">保 存</el-button>
  87. </span>
  88. </el-dialog>
  89. </div>
  90. </template>
  91. <script>
  92. import { fileUpload } from '@/api/app';
  93. export default {
  94. components: {},
  95. props: ['data'],
  96. data() {
  97. return {
  98. // ArticelData: JSON.parse(JSON.stringify(this.data)),
  99. showWordFlag: false,
  100. showPinyinFlag: false,
  101. showStyleFlag: false,
  102. remarkVisible: false,
  103. remark: null,
  104. activeItem: null,
  105. itemActive: null,
  106. activeIndex: null,
  107. };
  108. },
  109. // 生命周期 - 创建完成(可以访问当前this实例)
  110. created() {
  111. this.getArticleData();
  112. },
  113. methods: {
  114. // 获取分析结果
  115. getArticleData() {
  116. this.data.detail.forEach((item) => {
  117. if (item.segList && item.segList.length > 0) {
  118. item.sentenceStr = [];
  119. item.segList.forEach((items, indexs) => {
  120. let str = '';
  121. items.forEach((itemss, indexss) => {
  122. str += itemss;
  123. if (indexss !== items.length - 1) str += '&nbsp;&nbsp;';
  124. });
  125. item.sentenceStr.push(str);
  126. });
  127. }
  128. });
  129. },
  130. changeImage(file) {
  131. fileUpload('Mid', file, { isGlobalprogress: true }).then(({ file_info_list }) => {
  132. if (file_info_list.length > 0) {
  133. const { file_id, file_url_open, file_name } = file_info_list[0];
  134. this.remark.img_list.push({
  135. name: file_name,
  136. url: file_url_open,
  137. id: file_id,
  138. imgNumber: 0,
  139. });
  140. }
  141. });
  142. },
  143. delImage(index) {
  144. this.remark.img_list.splice(index, 1);
  145. },
  146. onBlur(item, field) {
  147. item[field] = item[field] ? item[field].trim() : '';
  148. },
  149. // 处理超出图片个数操作
  150. handleExceed(files, fileList) {
  151. this.$message.warning(
  152. `当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`,
  153. );
  154. },
  155. // 删除图片
  156. handleRemove() {
  157. setTimeout(() => {
  158. this.data.detail[this.activeIndex].sourceList = [];
  159. }, 100);
  160. },
  161. // 记录段落
  162. handleItem(index) {
  163. this.activeIndex = index;
  164. this.activeItem = this.data.detail[index];
  165. },
  166. // 图片上传前处理
  167. handleBeforeImage(file) {
  168. // 判断文件是否为图片
  169. if (!file.type.includes('image') && !file.type.includes('video')) {
  170. this.$message.error('请选择图片或视频文件');
  171. return false;
  172. }
  173. },
  174. // 图片上传
  175. handleImage(file) {
  176. fileUpload('Mid', file, { isGlobalprogress: true }).then(({ file_info_list }) => {
  177. if (file_info_list.length > 0) {
  178. this.activeItem.sourceList = file_info_list;
  179. this.activeItem.sourceList[0].name = file_info_list[0].file_name;
  180. this.activeItem.sourceList[0].type = file.file.type.includes('image') > -1 ? 'image' : 'video';
  181. }
  182. });
  183. },
  184. // 处理超出图片个数操作
  185. handleExceeds(files, fileList) {
  186. this.$message.warning(
  187. `当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`,
  188. );
  189. },
  190. // 删除图片
  191. handleRemoves() {
  192. this.itemActive.img = [];
  193. },
  194. // 图片上传前处理
  195. handleBeforeImages(file) {
  196. // 判断文件是否为图片
  197. if (!file.type.includes('image')) {
  198. this.$message.error('请选择图片文件');
  199. return false;
  200. }
  201. },
  202. // 图片上传
  203. handleImages(file) {
  204. fileUpload('Mid', file, { isGlobalprogress: true }).then(({ file_info_list }) => {
  205. if (file_info_list.length > 0) {
  206. this.itemActive.img = file_info_list;
  207. this.itemActive.img[0].name = file_info_list[0].file_name;
  208. }
  209. });
  210. },
  211. showPic(item) {
  212. this.itemActive = item;
  213. this.remarkVisible = true;
  214. },
  215. },
  216. };
  217. </script>
  218. <style lang="scss" scoped>
  219. .check-article {
  220. min-height: 100%;
  221. background: #f6f6f6;
  222. .wheader {
  223. background: #fff;
  224. }
  225. .main {
  226. background: #fff;
  227. &-top {
  228. position: relative;
  229. display: flex;
  230. align-items: center;
  231. justify-content: flex-end;
  232. margin-bottom: 24px;
  233. b {
  234. position: absolute;
  235. top: 0;
  236. left: 50%;
  237. width: 50px;
  238. margin-left: -25px;
  239. font-size: 24px;
  240. font-weight: 500;
  241. line-height: 34px;
  242. color: #000;
  243. text-align: center;
  244. }
  245. .el-button {
  246. padding: 5px 16px;
  247. font-size: 14px;
  248. font-weight: 400;
  249. line-height: 22px;
  250. color: #165dff;
  251. border: 1px solid #165dff;
  252. border-radius: 2px;
  253. &.el-button--primary {
  254. color: #fff;
  255. background: #165dff;
  256. }
  257. }
  258. }
  259. .go-back {
  260. display: flex;
  261. align-items: center;
  262. width: 60px;
  263. padding: 5px 8px;
  264. font-size: 14px;
  265. font-weight: 400;
  266. line-height: 22px;
  267. color: #333;
  268. cursor: pointer;
  269. background: #fff;
  270. border: 1px solid #d9d9d9;
  271. border-radius: 4px;
  272. box-shadow: 0 2px 0 0 rgba(0, 0, 0, 2%);
  273. .el-icon-arrow-left {
  274. margin-right: 8px;
  275. font-size: 16px;
  276. }
  277. }
  278. .paragraph {
  279. margin-bottom: 8px;
  280. text-align: center;
  281. > label {
  282. padding: 1px 8px;
  283. font-size: 14px;
  284. font-weight: 400;
  285. line-height: 22px;
  286. color: var(--blue-05, #175dff);
  287. background: #e7eeff;
  288. border: 1px solid #175dff;
  289. border-radius: 2px;
  290. }
  291. .sentence-box {
  292. .sentence {
  293. display: flex;
  294. flex-flow: wrap;
  295. margin-top: 8px;
  296. b {
  297. flex-shrink: 0;
  298. width: 32px;
  299. margin-top: 16px;
  300. font-size: 16px;
  301. font-weight: 400;
  302. line-height: 24px;
  303. color: #000;
  304. }
  305. .sentence {
  306. flex: 1;
  307. padding: 8px;
  308. font-size: 16px;
  309. font-weight: 400;
  310. line-height: 24px;
  311. color: #000;
  312. text-align: left;
  313. background: #f7f7f7;
  314. }
  315. }
  316. }
  317. }
  318. }
  319. .set-para {
  320. margin-top: 8px;
  321. text-align: left;
  322. }
  323. }
  324. .remark-box {
  325. display: flex;
  326. gap: 8px;
  327. align-items: center;
  328. justify-content: center;
  329. width: fit-content;
  330. height: 24px;
  331. padding: 2px 12px;
  332. margin: 16px 0 0;
  333. font-size: 12px;
  334. font-weight: 400;
  335. line-height: 20px; /* 166.667% */
  336. color: #165dff;
  337. cursor: pointer;
  338. border: 1px solid #165dff;
  339. border-radius: 2px;
  340. }
  341. .upload-resource {
  342. text-align: left;
  343. }
  344. .sentence-item {
  345. display: flex;
  346. flex-flow: wrap;
  347. align-items: center;
  348. }
  349. .sentence-pic {
  350. width: 10px;
  351. text-align: center;
  352. }
  353. </style>