You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.vue 11 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <div class="ui container">
  3. <div class="tuomin-title">
  4. <h2>{{ $t("dataDesensitizationModelExperience") }}</h2>
  5. <p>
  6. {{ $t("dataDesensitizationModelDesc") }} &nbsp;<a
  7. href="https://git.openi.org.cn/tengxiao/tuomin"
  8. target="_blank"
  9. >tengxiao / tuomin</a
  10. >
  11. </p>
  12. </div>
  13. <el-row :gutter="12" style="margin-top: 33px">
  14. <el-col :xs="24" :span="12">
  15. <div class="tuomin-content-image">
  16. <div class="tuomin-icon">
  17. <i
  18. class="ri-image-line"
  19. style="font-size: 16px; margin-right: 2px"
  20. ></i>
  21. <span style="font-size: 12px">img</span>
  22. </div>
  23. <div style="height: 230px; width: 96%; margin: 0 auto">
  24. <el-upload
  25. action="#"
  26. accept=".jpg,.jpeg,.png,.JPG,.JPEG,.PNG"
  27. :show-file-list="false"
  28. :on-change="handleChangePicture"
  29. list-type="picture-card"
  30. :file-list="fileList"
  31. :style="{ display: ImageUrl ? 'none' : 'block' }"
  32. :auto-upload="false"
  33. drag
  34. >
  35. <div class="el-upload__text">
  36. {{ $t("dragThePictureHere")
  37. }}<span style="color: rgba(136, 136, 136, 0.87)">{{
  38. $t("or")
  39. }}</span
  40. >{{ $t("clickUpload") }}
  41. </div>
  42. </el-upload>
  43. <img class="preview-image" v-if="ImageUrl" :src="ImageUrl" alt="" />
  44. </div>
  45. <div>
  46. <div class="tuomin-radio-model">
  47. <label class="radio-label"
  48. >{{ $t("desensitizationObject") }}:</label
  49. >
  50. <div>
  51. <el-radio-group v-model="radio">
  52. <el-radio :label="2">{{ $t("all") }}</el-radio>
  53. <el-radio :label="1">{{ $t("onlyFace") }}</el-radio>
  54. <el-radio :label="0">{{ $t("onlyLicensePlate") }}</el-radio>
  55. </el-radio-group>
  56. </div>
  57. </div>
  58. <div class="tuomin-button-model">
  59. <el-button @click="cancelUpload">{{ $t("cancel") }}</el-button>
  60. <el-button
  61. :disabled="fileList.length < 1"
  62. @click="startTranform"
  63. type="primary"
  64. >{{ $t("startDesensitization") }}</el-button
  65. >
  66. </div>
  67. </div>
  68. </div>
  69. </el-col>
  70. <el-col :xs="24" :span="12">
  71. <div class="tuomin-content-image" v-loading="tranformImageLoading">
  72. <div class="tuomin-icon">
  73. <i
  74. class="ri-image-line"
  75. style="font-size: 16px; margin-right: 2px"
  76. ></i>
  77. <span style="font-size: 12px">output</span>
  78. </div>
  79. <div
  80. v-if="resultImgSrc"
  81. class="tuomin-icon-download"
  82. @click="downImg"
  83. >
  84. <i
  85. class="ri-download-2-line"
  86. style="font-size: 16px; margin-right: 2px"
  87. ></i>
  88. <span style="font-size: 14px">下载</span>
  89. </div>
  90. <div style="height: 358px">
  91. <el-image
  92. style="height: 100%; width: 100%"
  93. :src="resultImgSrc"
  94. :preview-src-list="[resultImgSrc]"
  95. >
  96. <div slot="error" class="image-slot">
  97. <i style="font-size: 0" class="el-icon-picture-outline"></i>
  98. </div>
  99. </el-image>
  100. </div>
  101. </div>
  102. </el-col>
  103. </el-row>
  104. <div style="margin: 39px 0 21px 0">
  105. <span>{{ $t("example") }}:</span>
  106. </div>
  107. <div class="table-container">
  108. <div>
  109. <el-table border :data="tableData1" style="width: 100%">
  110. <el-table-column :label="$t('originPicture')" align="center">
  111. <template slot-scope="scope">
  112. <div style="width: 100%; height: 200px">
  113. <el-image
  114. style="height: 100%; width: 100%"
  115. :src="scope.row.imgSrc1"
  116. :preview-src-list="[scope.row.imgSrc1]"
  117. >
  118. <div slot="error" class="image-slot">
  119. <i style="font-size: 0" class="el-icon-picture-outline"></i>
  120. </div>
  121. </el-image>
  122. </div>
  123. </template>
  124. </el-table-column>
  125. <el-table-column :label="$t('desensitizationPicture')" align="center">
  126. <template slot-scope="scope">
  127. <div style="width: 100%; height: 200px">
  128. <el-image
  129. style="height: 100%; width: 100%"
  130. :src="scope.row.imgSrc2"
  131. :preview-src-list="[scope.row.imgSrc2]"
  132. >
  133. <div slot="error" class="image-slot">
  134. <i style="font-size: 0" class="el-icon-picture-outline"></i>
  135. </div>
  136. </el-image>
  137. </div>
  138. </template>
  139. </el-table-column>
  140. <el-table-column
  141. prop="mode"
  142. :label="$t('desensitizationObject')"
  143. align="center"
  144. header-align="center"
  145. >
  146. </el-table-column>
  147. </el-table>
  148. </div>
  149. </div>
  150. </div>
  151. </template>
  152. <script>
  153. import axios from "axios";
  154. export default {
  155. data() {
  156. return {
  157. ImageUrl: "",
  158. radio: 2,
  159. file: "",
  160. fileList: [],
  161. resultImgSrc: "",
  162. tranformImageLoading: false,
  163. tableData1: [
  164. {
  165. imgSrc1: "/img/origin.png",
  166. imgSrc2: "/img/tuomin.png",
  167. mode: this.$t("all"),
  168. },
  169. ],
  170. };
  171. },
  172. components: {},
  173. methods: {
  174. // 选择文件、移除文件、上传文件成功/失败后,都会触发
  175. handleChangePicture(file, fileList) {
  176. let acceptList = ["jpg", "jpeg", "png"];
  177. // 根据文件名获取文件的后缀名
  178. let fileType = file.name.split(".").pop().toLowerCase();
  179. // 判断文件格式是否符合要求
  180. if (acceptList.indexOf(fileType) === -1) {
  181. this.$message.error(this.$t("limitFilesUpload"));
  182. return false;
  183. }
  184. // 判断文件大小是否符合要求
  185. if (file.size / 1024 / 1024 > 20) {
  186. this.$message.error(this.$t("limitSizeUpload"));
  187. return false;
  188. }
  189. this.ImageUrl = URL.createObjectURL(file.raw);
  190. this.file = file;
  191. this.fileList = fileList;
  192. },
  193. cancelUpload() {
  194. this.ImageUrl = "";
  195. this.file = "";
  196. this.fileList = [];
  197. },
  198. downImg() {
  199. const a = document.createElement("a");
  200. a.download = "result.png";
  201. a.style.display = "none";
  202. a.href = this.resultImgSrc;
  203. document.body.appendChild(a);
  204. a.click();
  205. document.body.removeChild(a);
  206. },
  207. startTranform() {
  208. if (!this.file) return;
  209. let fd = new FormData();
  210. fd.append("file", this.file.raw);
  211. this.tranformImageLoading = true;
  212. axios({
  213. method: "POST",
  214. url: "/extension/tuomin/upload",
  215. headers: { Accept: "image/png" },
  216. responseType: "blob",
  217. params: { mode: this.radio },
  218. data: fd,
  219. })
  220. .then((res) => {
  221. const objectURL = URL.createObjectURL(res.data);
  222. this.resultImgSrc = objectURL;
  223. this.tranformImageLoading = false;
  224. })
  225. .catch((err) => {
  226. this.tranformImageLoading = false;
  227. if (err.response.status === 400) {
  228. const fr = new FileReader();
  229. fr.onload = (e) => {
  230. try {
  231. const jsonResult = JSON.parse(e.target.result);
  232. this.$message({
  233. type: "error",
  234. message: jsonResult.Message,
  235. });
  236. } catch (e) {
  237. this.$message({
  238. type: "error",
  239. message: this.$t("tranformImageFailed"),
  240. });
  241. }
  242. };
  243. fr.readAsText(err.response.data);
  244. } else {
  245. this.$message({
  246. type: "error",
  247. message: this.$t("tranformImageFailed"),
  248. });
  249. }
  250. });
  251. },
  252. },
  253. mounted() {},
  254. beforeDestroy() {},
  255. };
  256. </script>
  257. <style scoped lang="less">
  258. .tuomin-title {
  259. margin-top: 34px;
  260. h2 {
  261. display: flex;
  262. justify-content: center;
  263. }
  264. p {
  265. display: flex;
  266. justify-content: center;
  267. color: rgba(136, 136, 136, 0.87);
  268. }
  269. }
  270. .tuomin-content-image {
  271. border: 1px solid rgba(0, 0, 0, 0.1);
  272. border-radius: 5px;
  273. min-height: 358px;
  274. position: relative;
  275. .tuomin-icon {
  276. z-index: 99;
  277. display: flex;
  278. align-items: center;
  279. position: absolute;
  280. left: 0;
  281. top: 0;
  282. width: 66px;
  283. height: 22px;
  284. justify-content: center;
  285. color: rgba(136, 136, 136, 0.87);
  286. border-radius: 5px 0px 10px 0px;
  287. border: 1px solid rgba(0, 0, 0, 0.1);
  288. }
  289. .tuomin-icon-download {
  290. z-index: 99;
  291. display: flex;
  292. align-items: center;
  293. position: absolute;
  294. right: 10px;
  295. bottom: 10px;
  296. width: 66px;
  297. height: 30px;
  298. justify-content: center;
  299. color: rgba(255, 255, 255, 1);
  300. background-color: rgba(0, 0, 0, 0);
  301. background: transparent;
  302. border: 1px solid rgba(136, 136, 136, 0.5);
  303. border-radius: 4px;
  304. cursor: pointer;
  305. }
  306. .el-upload__text {
  307. height: 100%;
  308. display: flex;
  309. align-items: center;
  310. justify-content: center;
  311. }
  312. .preview-image {
  313. height: 100%;
  314. width: 100%;
  315. }
  316. .tuomin-radio-model {
  317. display: flex;
  318. margin: 25px 12px 0 12px;
  319. .radio-label {
  320. font-weight: 600;
  321. margin-right: 4px;
  322. color: rgba(16, 16, 16, 1);
  323. }
  324. }
  325. .tuomin-button-model {
  326. text-align: right;
  327. margin: 22px 12px 0 12px;
  328. }
  329. }
  330. /deep/ .el-upload--picture-card {
  331. width: 100%;
  332. background: #ffff;
  333. border: none;
  334. border-bottom: 1px dashed #888;
  335. border-radius: 0;
  336. min-height: 230px;
  337. }
  338. /deep/ .el-upload-dragger {
  339. width: 100%;
  340. background: #ffff;
  341. border: none;
  342. border-radius: 0;
  343. height: 100%;
  344. }
  345. .table-container {
  346. margin-bottom: 16px;
  347. /deep/ .el-table__header {
  348. th {
  349. background: rgb(245, 245, 246);
  350. font-size: 14px;
  351. color: rgb(36, 36, 36);
  352. font-weight: 400;
  353. }
  354. }
  355. /deep/ .el-table__body {
  356. td {
  357. font-size: 14px;
  358. }
  359. }
  360. }
  361. .center {
  362. display: flex;
  363. justify-content: center;
  364. }
  365. @media screen and (max-width: 768px) {
  366. body {
  367. background-color: black;
  368. }
  369. }
  370. </style>