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

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