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
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 { postImgDesensitization } from "~/apis/modules/desensitization";
  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. startFlag: false,
  171. };
  172. },
  173. components: {},
  174. methods: {
  175. // 选择文件、移除文件、上传文件成功/失败后,都会触发
  176. handleChangePicture(file, fileList) {
  177. let acceptList = ["jpg", "jpeg", "png"];
  178. // 根据文件名获取文件的后缀名
  179. let fileType = file.name.split(".").pop().toLowerCase();
  180. // 判断文件格式是否符合要求
  181. if (acceptList.indexOf(fileType) === -1) {
  182. this.$message.error(this.$t("limitFilesUpload"));
  183. return false;
  184. }
  185. // 判断文件大小是否符合要求
  186. if (file.size / 1024 / 1024 > 20) {
  187. this.$message.error(this.$t("limitSizeUpload"));
  188. return false;
  189. }
  190. this.ImageUrl = URL.createObjectURL(file.raw);
  191. this.file = file;
  192. this.fileList = fileList;
  193. },
  194. cancelUpload() {
  195. this.ImageUrl = "";
  196. this.file = "";
  197. this.fileList = [];
  198. },
  199. downImg() {
  200. const a = document.createElement("a");
  201. a.download = "result.png";
  202. a.style.display = "none";
  203. a.href = this.resultImgSrc;
  204. document.body.appendChild(a);
  205. a.click();
  206. document.body.removeChild(a);
  207. },
  208. startTranform() {
  209. if (!this.startFlag) {
  210. window.location.href = "/user/login";
  211. return;
  212. }
  213. if (!this.file) return;
  214. let fd = new FormData();
  215. fd.append("file", this.file.raw);
  216. this.tranformImageLoading = true;
  217. postImgDesensitization({ mode: this.radio }, fd)
  218. .then((res) => {
  219. const objectURL = URL.createObjectURL(res.data);
  220. this.resultImgSrc = objectURL;
  221. this.tranformImageLoading = false;
  222. })
  223. .catch((err) => {
  224. this.tranformImageLoading = false;
  225. if (err.response.status === 400) {
  226. const fr = new FileReader();
  227. fr.onload = (e) => {
  228. try {
  229. const jsonResult = JSON.parse(e.target.result);
  230. this.$message({
  231. type: "error",
  232. message: jsonResult.Message,
  233. });
  234. } catch (e) {
  235. this.$message({
  236. type: "error",
  237. message: this.$t("tranformImageFailed"),
  238. });
  239. }
  240. };
  241. fr.readAsText(err.response.data);
  242. } else {
  243. this.$message({
  244. type: "error",
  245. message: this.$t("tranformImageFailed"),
  246. });
  247. }
  248. });
  249. },
  250. },
  251. mounted() {
  252. const signEl = document.querySelector("#isSignd");
  253. this.startFlag = !!signEl.getAttribute("data-sign");
  254. },
  255. beforeDestroy() {},
  256. };
  257. </script>
  258. <style scoped lang="less">
  259. .tuomin-title {
  260. margin-top: 34px;
  261. h2 {
  262. display: flex;
  263. justify-content: center;
  264. }
  265. p {
  266. display: flex;
  267. justify-content: center;
  268. color: rgba(136, 136, 136, 0.87);
  269. }
  270. }
  271. .tuomin-content-image {
  272. border: 1px solid rgba(0, 0, 0, 0.1);
  273. border-radius: 5px;
  274. min-height: 358px;
  275. position: relative;
  276. .tuomin-icon {
  277. z-index: 99;
  278. display: flex;
  279. align-items: center;
  280. position: absolute;
  281. left: 0;
  282. top: 0;
  283. width: 66px;
  284. height: 22px;
  285. justify-content: center;
  286. color: rgba(136, 136, 136, 0.87);
  287. border-radius: 5px 0px 10px 0px;
  288. border: 1px solid rgba(0, 0, 0, 0.1);
  289. }
  290. .tuomin-icon-download {
  291. z-index: 99;
  292. display: flex;
  293. align-items: center;
  294. position: absolute;
  295. right: 10px;
  296. bottom: 10px;
  297. width: 66px;
  298. height: 30px;
  299. justify-content: center;
  300. color: rgba(255, 255, 255, 1);
  301. background-color: rgba(0, 0, 0, 0);
  302. background: transparent;
  303. border: 1px solid rgba(136, 136, 136, 0.5);
  304. border-radius: 4px;
  305. cursor: pointer;
  306. }
  307. .el-upload__text {
  308. height: 100%;
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. }
  313. .preview-image {
  314. height: 100%;
  315. width: 100%;
  316. }
  317. .tuomin-radio-model {
  318. display: flex;
  319. margin: 25px 12px 0 12px;
  320. .radio-label {
  321. font-weight: 600;
  322. margin-right: 4px;
  323. color: rgba(16, 16, 16, 1);
  324. }
  325. }
  326. .tuomin-button-model {
  327. text-align: right;
  328. margin: 22px 12px 0 12px;
  329. }
  330. }
  331. /deep/ .el-upload--picture-card {
  332. width: 100%;
  333. background: #ffff;
  334. border: none;
  335. border-bottom: 1px dashed #888;
  336. border-radius: 0;
  337. min-height: 230px;
  338. }
  339. /deep/ .el-upload-dragger {
  340. width: 100%;
  341. background: #ffff;
  342. border: none;
  343. border-radius: 0;
  344. height: 100%;
  345. }
  346. .table-container {
  347. margin-bottom: 16px;
  348. /deep/ .el-table__header {
  349. th {
  350. background: rgb(245, 245, 246);
  351. font-size: 14px;
  352. color: rgb(36, 36, 36);
  353. font-weight: 400;
  354. }
  355. }
  356. /deep/ .el-table__body {
  357. td {
  358. font-size: 14px;
  359. }
  360. }
  361. }
  362. .center {
  363. display: flex;
  364. justify-content: center;
  365. }
  366. @media screen and (max-width: 768px) {
  367. body {
  368. background-color: black;
  369. }
  370. }
  371. </style>