找回密码
 加入怎通
查看: 197|回复: 0

前端设计走查平台实践(前端篇)(走前端要学java吗)

[复制链接]
我来看看 发表于 2023-03-19 07:13:29 | 显示全部楼层 |阅读模式
9 D1 E* A2 F/ X* e$ h* t

项目背景

n1 |% R n% f: b' y$ n

随着前端业务的不断发展,前端对设计稿的还原程度也成为了影响用户对产品体验的一个关键指标,作为最靠近用户侧的研发,前端工程师通常需要和设计师同学通力配合来提升用户体验其中,设计走查是设计同学最常见的测试前端同学是否完美还原了自己设计理念的方式,本文旨在通过设计走查平台在前端侧的实践总结下在前端上游研发链路中的一些基础建设,以期能够为其他有相关需要的同学提供一些实践思路。

0 s! x& E0 R' k( r# Z2 k9 M

方案

* X! D/ l' @ P0 M

一个前端工程师的主要目标是寻找一款贴近浏览器原生的框架,svelte 是你不二的选择前端架构选型,从整体的产品业务形态来看,属于较为简单的单一页面形态,并且考虑到要支持浏览器的插件生态,因而前端部分选择使用了。

$ \) y9 T: L4 R. m. N2 c( ]

svelte的框架方案选择 svelte 作为本业务的前端技术选型主要考虑到以下两方面原因:一是考虑到业务形态较为简单,只有一个上传图片的页面;二是由于浏览器插件相关的编写还是更加偏向原生js一些,使用大型框架有些大材小用。

6 x/ |0 K2 {5 z* B% D6 E

综合近几年 svelte 的迅猛发展,小型业务还是考虑使用它作为一个框架使用的,其在编译时利用位掩码做的脏值检查的思路其实还是可以作为框架开发者借鉴的一个思路的(ps:对这个感兴趣的同学,可以看一下新兴前端框架 Svelte 从入门到原理

6 r8 c: O( @& r* z& J; F

这篇文章的介绍),但是目前发展相对还是比较初期,整个生态相对还不够完善,同时也是给广大开发者提供了很好的蓝海空间,比如:目前还没有出现类似 Element UI 和 Ant Design 这种十分好用的组件库系统,虽然有几个,但是个人感觉很不好用,作者在本项目中对需要用到的几个组件做了简单的封装,有需要的同学可以参考借鉴一下。

/ B- I u, A: ]7 ?6 K

目录public buildbg.jpegfavicon.pngglobal.cssindex.htmlmanifest.jsonscripts setupCrxScript.jssetupTypeScript.js

% ^" }6 K" y# X* n+ c" E( |

src components Button.svelteDialog.svelteIcon.svelteInput.svelteMessage.svelteTooltip.svelteUpload.svelte

# F* n$ }! Q1 p* _; ] p- f

utils function.jsimage.jsindex.jsApp.sveltemain.jsrollup.config.js实践

( X2 R9 a4 X6 R% H6 {; I9 a6 v; v$ _

设计走查平台提供了管理平台及对应的Chrome插件,可提供给测试及UI同学用于图片的比对,提升研发效率源码

- u# p# L( f1 X. S8 ~

svelte作者--前端著名的轮子哥Rich Harris,同时也是rollup的作者,因而本项目中就选择了 rollup 作为打包构建的工具,同时为了将Chrome插件发布到内网中(ps:本项目主要用于项目内部基建应用,因而未在公有云及Chrome官方平台去发布,服务端涉及到了图片的比对计算);在scripts目录下内置了两个脚本,一个用于生成ts,一个用于向云平台发送压缩包;由于

( Z9 e5 q+ x' |9 G2 K5 F( r

svelte 的组件库生态相对不是特别丰富(ps:业界常见已经开源的 svelte 组件库可以参看这篇文章Svelte的UI组件库),对比了业界几个相关的组件库后,决定自己实现下业务中需要用到的组件,具体组件放在了components目录下

n/ \& f. O" U

rollup.config.jsimportsveltefromrollup-plugin-svelte;importcommonjsfrom@rollup/plugin-commonjs;import

; v3 t* v% R) n4 ~ n- O

resolvefrom@rollup/plugin-node-resolve;importlivereloadfromrollup-plugin-livereload;import{terser}from

6 s: v9 J' r) C- z5 y

rollup-plugin-terser;importcssfromrollup-plugin-css-only;constproduction=!process.env.ROLLUP_WATCH;function

1 }! d6 Z w. I/ z7 q1 w

serve(){letserver;functiontoExit(){if(server)server.kill(0);}return{writeBundle(){if(server)return;server

5 o3 j) M. \1 w. M1 F+ o% p

=require(child_process).spawn(npm,[run,start,--,--dev],{stdio:[ignore,inherit,inherit],shell:true});process

, [% x l0 N' ^

.on(SIGTERM,toExit);process.on(exit,toExit);}};}exportdefault{input:src/main.js,output:{sourcemap:true

3 Z4 i' H, {0 \& M* N

,format:iife,name:app,file:public/build/bundle.js},plugins:[svelte({compilerOptions:{// enable run-time checks when not in production. k/ N4 a/ t- ^+ ]9 a% w1 _) |

( p1 x' t' ~ u; P

dev:!production}}),// well extract any component CSS out into( C' h* j9 Z2 F* s" d+ r // a separate file - better for performance, S* d/ Z$ h0 {$ q; c# p

5 ^8 r0 k* W- M7 c# f$ d

css({output:bundle.css}),// If you have external dependencies installed from _1 c- U) t. P; h // npm, youll most likely need these plugins. In # v0 X+ ~2 @% t0 B

( b. d/ u" z; Z2 _; {5 L# f

// some cases youll need additional configuration - 1 u6 L) B2 ^+ z+ U/ \- }& g // consult the documentation for details:" |8 Y6 k: u! I/ g" k // https://github.com/rollup/plugins/tree/master/packages/commonjs* `. q T9 R- j7 {$ k4 ]/ q1 o% ~. U

/ g& Q' O6 z; U1 k

resolve({browser:true,dedupe:[svelte]}),commonjs(),// In dev mode, call `npm run start` once 0 m+ `' w0 E; P1 c- c7 @0 @ // the bundle has been generated# K3 C& X" f/ ]% [" ~+ y

" N' t# b2 I! ~7 Q% R8 N

!production&&serve(),// Watch the `public` directory and refresh the# E7 |4 j# S/ d& t# a( z! m! J // browser on changes when not in production ' T4 W \, V6 V9 W

. m' H: B J9 N0 @- @* C

!production&&livereload(public),// If were building for production (npm run build ( h9 P5 f' d ? // instead of npm run dev), minify `! c U7 J' j9 w% C1 v6 O( K/ v

3 v3 i* T+ i, r& G" R. g

production&&terser()],watch:{clearScreen:false}};scriptssetupCrxScript.js通过minio这个库来进行私有云平台的对象存储库上传,archiver

% y* s7 o, ~, M9 R- P

这个主要用于压缩constfs=require(fs);constpath=require(path);constarchiver=require(archiver);constMinio=require

h* G8 I6 A( X1 A7 J, k

(minio);constminio=newMinio.Client({endPoint:,port:80,useSSL:false,accessKey:,secretKey:})constoutput

* w! L8 A' P; S3 ^. E% t5 x

=fs.createWriteStream(path.resolve(__dirname,../pixelpiper.zip));constarchive=archiver(zip,{zlib:{level

: u& ~& F4 U) m6 C0 v4 s$ r3 a. S

:9}});output.on(close,function(){console.log(archive.pointer()+ total bytes);console.log(archiver has been finalized and the output file descriptor has closed.

h- D: t* M; e5 k

);// 压缩完成后向 cdn 中传递压缩包: S' t$ h. h$ ?8 i3 Q constfile=path.resolve(__dirname,../pixelpiper.zip);fs.stat(file,function(error

+ q' I6 S K* D8 c6 h: d0 h& K- b

,stats){if(error){returnconsole.error(error)}minio.putObject(cdn,pixelpiper.zip,fs.createReadStream(file

! b5 d, C, o; W$ P8 N. L% O6 Y7 V

),stats.size,application/zip,function(err,etag){returnconsole.log(err,etag)// err should be null. k2 L7 r5 R* k })})

$ V# T/ E" E9 E! p: }

});output.on(end,function(){console.log(Data has been drained);});archive.on(warning,function(err){if

/ h! L7 i- [4 O5 e

(err.code===ENOENT){}else{throwerr;}});archive.on(error,function(err){throwerr;});archive.pipe(output

2 z; C# `5 U, f7 F4 q7 d4 t- f

);archive.directory(path.resolve(__dirname,../public),false);archive.finalize();setupTypeScript.js// @ts-check ! l1 T' j, D8 P- Q& n2 u! s

( d, X2 b. x) z6 x1 K3 D3 {

/** This script modifies the project to support TS code in .svelte files like:* \$ ^2 B6 j1 ^1 l% e: Z I/ A5 B# ?6 s export let name: string; ; Y) t, Z, |. r1 I8 c

6 H+ M- X2 G% B# t4 P7 ^) G/ W' ^

9 N, V3 h+ I C/ b$ t8 m7 T As well as validating the code for CI.( _0 x& w& o3 y O" { r4 ^6 w *//** To work on this script:) f0 h9 X' ]6 o0 v rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template # |1 h7 b: ~/ S9 j# z

- h8 Q! \& ]- |

*/constfs=require("fs")constpath=require("path")const{argv}=require("process")constprojectRoot=argv[2

8 G# a% W, j/ F- T6 l* X

]||path.join(__dirname,"..")// Add deps to pkg.json 7 J0 n, `3 a) w) V constpackageJSON=JSON.parse(fs.readFileSync(path.

& `3 P5 X7 |# X# t: i

join(projectRoot,"package.json"),"utf8"))packageJSON.devDependencies=Object.assign(packageJSON.devDependencies

% n1 {; r3 y6 Y" i, y2 B

,{"svelte-check":"^1.0.0","svelte-preprocess":"^4.0.0","@rollup/plugin-typescript":"^8.0.0","typescript"

, e+ X- t; h8 D; {) l

:"^4.0.0","tslib":"^2.0.0","@tsconfig/svelte":"^1.0.0"})// Add script for checking' N. C8 C' ~4 W9 l- V5 x: R packageJSON.scripts

`9 c4 r; g; w2 R

=Object.assign(packageJSON.scripts,{"validate":"svelte-check"})// Write the package JSON # h6 X/ k( m0 L6 p+ w" Y fs.writeFileSync

, j7 d) ?" U7 w0 Q$ [- D0 D1 ]- ?

(path.join(projectRoot,"package.json"),JSON.stringify(packageJSON,null," "))// mv src/main.js to main.ts - note, we need to edit rollup.config.js for this too% N$ ~9 f5 p3 Q$ {

& U. T0 U+ }( j! U2 F

constbeforeMainJSPath=path.join(projectRoot,"src","main.js")constafterMainTSPath=path.join(projectRoot

0 a1 F1 c6 a% H5 L

,"src","main.ts")fs.renameSync(beforeMainJSPath,afterMainTSPath)// Switch the app.svelte file to use TS , C, z L) Z. V0 ?) O6 q

, P3 P1 r) M7 b7 j/ r& O

constappSveltePath=path.join(projectRoot,"src","App.svelte")letappFile=fs.readFileSync(appSveltePath,

, c; n2 t, J+ v, T e9 T# G4 |

"utf8")appFile=appFile.replace("",)appFile=appFile.replace("export let name;"

8 g# s6 Z0 F% b' Q0 `! y2 `/ I" Y0 B

,export let name: string;)fs.writeFileSync(appSveltePath,appFile)// Edit rollup config : W; @" p: C" } c% f constrollupConfigPath

, g& s1 u$ N: W; X! Y: A0 u( ~

=path.join(projectRoot,"rollup.config.js")letrollupConfig=fs.readFileSync(rollupConfigPath,"utf8")// Edit imports5 @. q! `& J* B- M6 \( o

/ Z( [$ t$ q! Y8 W

rollupConfig=rollupConfig.replace(`rollup-plugin-terser;`,`rollup-plugin-terser; 7 G, F$ l1 y0 K. W import sveltePreprocess from svelte-preprocess; ) t L8 H3 s7 r7 E4 u

3 i( g- g0 l5 o1 I! }* x

import typescript from @rollup/plugin-typescript;`)// Replace name of entry point * u+ G/ b( o: O6 U3 t0 V rollupConfig=rollupConfig

; o$ w5 W' h+ y5 W( S

.replace(`src/main.js`,`src/main.ts`)// Add preprocessor3 r3 x& m- k4 J7 ` P% p; p2 P rollupConfig=rollupConfig.replace(compilerOptions:

1 O1 G& C6 G1 T2 V# b

,preprocess: sveltePreprocess({ sourceMap: !production }),\n\t\t\tcompilerOptions:);// Add TypeScript - v$ z4 W# ~3 _3 }

0 C* E( y- C0 v7 p _

rollupConfig=rollupConfig.replace(commonjs(),,commonjs(),\n\t\ttypescript({\n\t\t\tsourceMap: !production,\n\t\t\tinlineSources: !production\n\t\t}),

' t$ A0 ? d; {% y! O$ n( }* E. t

);fs.writeFileSync(rollupConfigPath,rollupConfig)// Add TSConfig4 D5 H2 r4 A, c. w* c# Z4 k. d4 Z0 T consttsconfig=`{" b5 }% Q; K l "extends": "@tsconfig/svelte/tsconfig.json", % }) ^. S; r# y+ l0 j9 Q

, Z0 h+ I f9 L6 p9 D1 u

"include": ["src/**/*"],( [; r* M- P. X! M$ M; b$ I9 h5 t "exclude": ["node_modules/*", "__sapper__/*", "public/*"] 7 a: T. h0 {5 |- y" J: J5 J; f( G }`consttsconfigPath

4 C# t9 E* s6 T

=path.join(projectRoot,"tsconfig.json")fs.writeFileSync(tsconfigPath,tsconfig)// Delete this script, but not during testing& I& K% k" E, ?2 _

4 L x6 j1 q2 H1 y- P8 |; M: S9 Z

if(!argv[2]){// Remove the script ! ^# [7 p8 \ n$ ]2 F; _5 R% U fs.unlinkSync(path.join(__filename))// Check for Macs DS_store file, and if its the only one left remove it4 ?2 |# b. V& L& J

0 g0 V$ l7 j1 y' z

constremainingFiles=fs.readdirSync(path.join(__dirname))if(remainingFiles.length===1&&remainingFiles[

. D! x1 V8 L0 E, V4 V9 c* c* c& L# _8 _

0]===.DS_store){fs.unlinkSync(path.join(__dirname,.DS_store))}// Check if the scripts folder is empty) Q' |3 h, N% f J+ v4 ?

: L/ c7 T7 K3 T! t- p2 M; q( R7 ]- h

if(fs.readdirSync(path.join(__dirname)).length===0){// Remove the scripts folder/ N' Y0 z9 r3 K% p4 d fs.rmdirSync(path.join

- o: O* G4 j$ H+ f5 y

(__dirname))}}// Adds the extension recommendation ! j& ^* J1 E7 \/ ~0 ~ T1 e fs.mkdirSync(path.join(projectRoot,".vscode"),{recursive

( R5 q8 F" \; T' `( _) H! m/ v

:true})fs.writeFileSync(path.join(projectRoot,".vscode","extensions.json"),`{8 g$ \0 j: X$ | "recommendations": ["svelte.svelte-vscode"] , r% `# q Y0 D7 o

* s0 V) p2 O) b4 o h+ w3 l- @

} 4 L4 \! j( j4 I6 s8 w `)console.log("Converted to TypeScript.")if(fs.existsSync(path.join(projectRoot,"node_modules"))){console

. d0 ]6 \2 p" P( p

.log("\nYou will need to re-run your dependency manager to get started.")}components项目中用到了一些通用组件,借鉴了下

^( |+ B9 ^& }4 H1 @' a. I

Element UI的组件样式和思路,主要封装了 Button(按钮) 、 Dialog(对话框) 、 Icon(图标) 、 Input(输入框) 、 Message(消息) 、 Tooltip(提示工具)

% T7 |8 Y- [' X+ A# s+ K; J* Q& q

、 Upload(上传) 几个组件Button.svelte9 Z9 @3 h. `) E0 ~$ h import Icon from ./Icon.svelte; N! |1 B8 \) f2 { import { createEventDispatcher } from svelte;& F+ s# @+ O& h4 t4 i# p6 x const dispatch = createEventDispatcher();$ `* Q& Z6 A C; Y5 [8 P. d export let icon, type=default; " s, V" ]2 k) X- [3 [# M function handleClick() {5 N% V# H9 x3 W; L9 W dispatch(click)/ G- `! k2 r3 ?8 D# V) V C7 ^ } 6 e% S3 T# [5 j! N5 |+ Q; C1 ^ function computedButtonClass(type) {2 C6 L* s$ M" x+ b1 c" N6 H switch (type) { ; l) N) L3 O3 C7 w+ W case primary: ! D' \- g2 M- X& Y$ t7 u return button button-primary;& w- F/ G; C" J0 m case default: 0 l4 ~1 Y/ n1 }" I8 N return button button-default;5 n% y/ I: o0 T* [4 Z3 b* x* K% [ case text: ) B+ M% H' r- ]! o- f' q return button button-text; $ V4 m0 b9 d, \% r7 i: R5 \ default: 6 k1 Q& z+ U1 K return button button-default; ! }% u, `: |8 P, T } ! W" [' P1 }$ y3 U l }3 m" V# k3 v$ s- V- G- \, } ( |1 S, A4 _! Q1 a# t& k# Z, X+ [# v* t8 I9 q: Q ; {7 {+ k3 a# \7 o% k; o, Q# K- [& C( v .button {7 q( D, t9 Y$ T* Y' b border: 0; ) Y z) d( w# ~" U1 e" J6 ? border-radius: 2px; - Q- I; L. r }+ ~0 H0 [! z }1 O5 h- c; o ? - K; Q6 r+ e; s! `4 O" \ .button:hover { / U: T# t( t6 B0 a( H) L: S cursor: pointer;, x( J$ Y* Y. c" ^8 o }; {7 E( s6 z3 q 5 u' U* }& x' p8 N3 `# O7 S5 k .button-primary { 2 q6 Y. ~ c# x. j: W$ \5 d4 x background-color: rgb(77, 187, 41, 1); ' \9 n& B0 u, E$ O3 z! \* `* Q; \, t color: white;* E. |0 R: G7 G/ |4 Z border: 1px solid rgb(77, 187, 41, 1); 7 g/ p8 H! S$ F" M( [ } 8 m3 f) y& X: a K( `, g2 \$ _2 g) F5 x# e- F; R2 l) ~2 p) I .button-primary:hover {1 @0 Q5 _8 @' i% \2 N Y5 j" a7 M background-color: rgba(77, 187, 41,.8);; U+ Y, L5 R* ?' o' M } 8 T% p# _" @3 C' E* m( M( k4 G* k6 e3 z* ~6 T! S .button-default {5 d6 p, P3 S. x/ n background-color: white;$ `* g, a0 ^0 i! D" G' b0 c- b* O color: #999; $ K- R! V- Q# u( p& Z e border: 1px solid #e0e0e0;8 N8 D Z- Z# R } 5 `& [4 F* B: @, R$ K 8 l- X5 b4 R5 z) H, X .button-default:hover { 3 k9 M- b F% |5 N% L background-color: rgba(77, 187, 41,.1); ; z& _/ y& ?* E color: rgba(77, 187, 41,.6);0 U3 U+ W5 R! H border: 1px solid #e0e0e0; $ ~% H" L9 G; {5 T/ y }6 M% H \9 O( T4 a9 x - _2 _3 ~1 r: V4 V# ~( l$ c8 O .button-text { * q* [* E1 ^- {4 I3 s; Q background-color: transparent;0 i/ Y1 p9 c2 m! G border: none; ( ~' }* K7 A4 t$ Z/ y! ^ } , [5 W& W" J2 I& R2 n( e+ C' f: r. C 8 r) u# ^$ B5 M+ @( { ) a& X4 Y( m$ O6 ~7 K {#if icon}5 g% P$ \6 ^% h 0 F- w. C+ W8 O; x" v: Y6 X {/if}% t: m L; K# l1 G3 y* R# ^ {% Y: o7 h3 v7 r+ q

Dialog.svelte% _. r: S0 Z- Y7 m Q. w* {: e, \ import Icon from "./Icon.svelte";/ c' ~# |( b5 F import Button from "./Button.svelte"; ( J% r0 X8 t: \% k, M$ @0 Bimport { createEventDispatcher } from svelte; ! u7 b1 {4 W2 k! ?3 d1 s7 _const dispatch = createEventDispatcher(); ( M( j* J: D) aexport let title, visible = false;- U7 P5 z: Z: a3 r# o k function handleClose() {" W1 g8 S( h$ T7 T visible = false; 4 L4 p7 c+ F! ^. X1 Y" s}4 b; f; k5 w% K function handleShade() { - m( V3 C- W& V. e1 Y. g visible = false;. x, \. H+ @/ z } 8 s* I1 J8 E1 K% f. F) Zfunction handleCancel() {% r6 L) a9 K1 f+ d, ?1 U& n* v visible = false;4 x/ u6 h2 S! l8 u, Y8 b+ V } 6 C U' e& Z( s( [9 _function handleSubmit() { 0 Y# g w3 m @0 R/ T0 o- U$ U dispatch(submit) 9 @( Z# p0 i# F' s0 w$ N}+ D/ W/ B; d9 @8 D $ Z5 p; l% I4 }& V( e 1 `$ |0 Z& C F) Y* A , `3 X0 y; R5 ^$ |* P.dialog-wrapper { 1 Q( k" R* E$ a* @# g width: 100vw; 1 t" n# g; P9 z ^ A ^ height: 100vh; 5 N e( r# e" E( _ position: absolute;3 _, ?4 a# u* \9 k) L. Z0 ] z-index: 100000;7 ]. b% N: \ m! M( u I background-color: rgba(0, 0, 0, .3); 4 a8 F/ {, u$ m} 2 n% Y8 \8 i, ` [ r: `& S 2 {- M: t( F+ a1 a/ ?5 \! y.dialog { 4 z' [2 q7 ?( F2 ]1 _ width: 400px; $ |0 |- ]$ O0 _" ^ height: max-content; 3 i) M$ {/ ]4 e; e! |3 B0 e background-color: white; / Y/ p' G: X/ o) S$ G+ C$ f% U+ ? box-shadow: 0 0 10px #ececec;; \, j; z5 V$ c0 f; D position: absolute; 1 p( r3 a* E% ]) c- T4 C z-index: 100001; : z& x- F) P# s$ o border-radius: 2px; # A9 @' Y, o4 t4 v margin: auto;9 ^8 ~! u' m) C$ S' P top: 0;2 A! G; t7 O) `( c5 C% O0 B8 \, W bottom: 0;4 M' @/ Z7 r5 b# ?6 w/ y5 L( |1 A left: 0; - U. m z5 }! a7 z. C6 [# f right: 0; 2 c4 v' V# X/ Y: d} I! X/ y5 I* `/ x) v.dialog-header {" E* Y" V! m" ^% u- w: | display: flex; ; _: H* d9 ~# N2 V align-items: center; 8 c2 i; e$ q3 G justify-content: space-between; E$ \# l4 `: `/ [$ I% A+ f- Z" n border-bottom: 1px solid #ececec; , ~. M% X9 t( |/ e, W2 X' b. A' r padding: 10px; 0 g, U! b; J( Z} k4 T# ?4 x8 u( f2 U2 ?5 m* H4 x - j+ T8 b6 j. H. l! m Q" \ .dialog-header .dialog-title { ) n1 ]) N$ U# O- f: J/ j$ N7 n font-size: 16px; * G) q9 s" T: S' ?/ j6 Z}* n) n4 {6 R+ S0 L' d ~+ }* m1 b+ P, n+ r K& u& D+ F @3 @! e# p4 ~9 |/ D+ H .dialog-body { 4 p) ]. G% F/ M" Z, J padding: 10px;4 V- a% X; s! R6 d+ z: I }0 Z. _, X( w K# `) o! s + r2 v7 t5 a" H. w.dialog-footer { " R: N6 _0 C. I display: flex;2 Y& ^! ~$ I& v$ W$ S' ] justify-content: right; % N, i$ k9 N' m0 D7 @ padding: 10px; 9 W1 t8 T# l& @! w}6 ^) c; V9 ~- l 2 \4 k- D4 P4 K9 |% r % L, F, W& O4 `# n. x7 U{#if visible} ( {! L# ]" i* x0 e+ J2 N

0 d, ~- I9 w! t+ o* J
0 k5 R9 K- G1 B5 C" g7 R
`5 b! D4 n4 Z1 y l( C7 n8 B 5 x. D9 d/ x$ v6 `5 n { title }* y L. t, v% J$ x6 e 2 U! Y) h$ @( y' r ' A5 Q3 a$ W6 l, `% U. e: ?3 N' ] : I. k- V2 X/ ^9 B! U1 Y/ p ! w( J0 M* \" N( V) @6 f " d- Y0 q- A9 s; l
9 q0 |* I4 @: m/ L+ C" { 1 h& D8 h0 O5 ^/ @0 @
5 w5 D! e$ A5 U$ A h2 f O: n; x5 j
$ C Q! p9 H1 d& ?) e1 N/ M 取消 ; P, c9 o( h. H5 O# a1 B8 o+ M, _ 确定4 p& {' k% U2 B+ B ^* ?. \
9 c9 a/ ]9 Z' `) W5 F; D( ^3 V; Q
7 ]1 ? n) b( x+ ~ W$ H
* h; o# J& U+ q' F9 |{/if}

Icon.svelte常用的icon主要通过iconfont来引入 4 H: Q# Q# @9 p0 e5 A N export let name; " R0 p, l& c l7 G ' ]% g- E% n$ U/ x% p " O6 \* v. W2 U4 N( |1 u

Input.svelte ' ? d, U6 }9 e3 }9 t. S0 G export let value;& z% Z+ l2 T5 _ import { createEventDispatcher } from svelte; x7 J! X" O! T const dispatch = createEventDispatcher(); / \; o) ?& S9 M( i function handleChange() {4 C0 \( H5 _! A2 ^2 I2 p7 G( M0 V$ _ dispatch(input) : z. R3 R# R* _+ K0 O6 U } ' x p: f; r) K, d; t. b, e $ C9 `9 c( ]2 {( J( e C% U! K+ `' `, U / u% k# ~$ |. |$ H& r/ N .input { ( Y8 P3 l" j V border: 1px solid rgb(77, 187, 41, 1); , Z; N: f, x" l& z- C/ `: Y3 |5 O width: 100px;: G# @8 k: d6 `4 f5 W3 T7 x! Z1 ~ }- S' |7 e1 O- ?7 x0 Y $ k/ ^0 D, Q# {' F# O3 Z$ t .input:focus { 3 M1 `2 q6 s4 b5 W* G9 F i# | border: 1px solid rgb(77, 187, 41, .5);4 G# A% S: q }; L outline: none; ; V; A/ ~/ |* a; L/ C8 h. H8 F5 u } 0 d, f5 n8 W4 y% e3 Q. r+ g$ h# s, g# ]2 f. I7 R$ A . m# z5 ]% E8 r0 h0 c5 Z& b1 l. b

Message.svelte0 ?: U& j6 J6 Z import Icon from ./Icon.svelte; : j0 d' _0 S: A+ Vexport let type = info, show = false;. T; e& ^8 E+ u# J2 d9 X7 @ 8 |% w# Y, |' r$ P& D3 r Yconst computedMessageClass = type => { 6 \; J' i) l/ [6 F! [ switch (type) { % B# L6 L" \$ w" a' I6 ?9 l; f case success:# V. Z. ~5 ^4 v8 Z- ` return message message-success; * g! s4 T! b+ x case warning:0 Z! M* }- T8 N return message message-warning;* k$ S( P6 g+ v1 T2 j: F4 a case info: ! l+ M5 `( o% @% q return message message-info;! K( d2 J; m$ \7 V case error:: Y$ `" \9 L5 u& Q" X return message message-error;0 ?/ I1 } c6 J, ?$ T. X default:' b' V$ l( G P+ ~7 s) Q' H e return message message-info; & X) ` e- T/ o8 r( x2 P7 S! ~ } 8 f6 ?* G8 N, S& O% G" j$ H& D} , E0 W2 I$ z4 m* l 8 ]6 _8 j9 B; V$ b- s" T2 mconst computedIconName = type => { 9 r0 ^( @+ X6 J8 u- E: I9 S# h switch (type) {4 U8 N/ i7 {0 U( h5 c$ H4 W5 e! S | case success: Q" v% n' b2 s return iconsuccess; . R$ r% M! v1 j# C. | case warning: " J" ]" v/ M- B. j4 r ?$ U return iconwarning;$ T8 q( O. r( g: K, c" Y/ Z$ R/ V case info: & u( L2 k2 m( Z8 d; V5 \ return iconinfo;+ ~6 ]1 Z, X9 N, x& W, w7 | case error:4 T% F, m" L7 D9 P' j: ? return iconerror;, m) K) {1 _0 ^8 \ default:8 g9 `% A6 S5 Y ^2 p( E- E return iconinfo;4 T) u }$ I) @' w, t } . `! g r% ] b |} 1 L7 m9 K1 T1 Z q4 G! E 7 }: U( u/ X& r$ |. o, ?) P6 \+ k7 O% e - T& x1 n" z- v/ j, p/ M X. W# [7 \ .message {& w8 O7 }9 m/ H$ N0 d; ^- A$ P position: absolute; 2 o' }* |2 \* ?( J, ]: Y z-index: 100000;' P) f( U3 O$ L" c$ d2 N width: 200px;6 O$ U! ?7 f# W$ b& E height: max-content; * p4 [* W3 \- ~4 |6 S: O left: 0;, \7 O/ C3 ~/ P& R; G7 ^, i* E8 b right: 0;# T) g$ ^$ i0 o b! H' w& H margin: auto; Z$ z5 S0 F: q padding: 4px 10px;7 ?! j, W- U d- m+ B- x) y0 n animation: show 2s ease-in-out forwards; + a6 [& |/ N" x' g9 q display: flex;- J& E4 U! S6 H% j, U3 e% t% _ justify-content: left; 5 D' |# c, r* j: S3 H( V align-items: center; ' [5 P# o0 p2 `! l border-radius: 4px; $ w: B( T* P5 V) ?} + v9 i* C, K1 j, d% {; J k0 s- G" C7 W- O4 I9 ]2 q! d3 b' l .message-content {: c. o% O' k1 P7 y margin-left: 10px; 9 M+ x X2 ^: C! m}4 }8 Q2 t: e- T8 o . H2 F- f c0 y4 ^4 y2 q6 ?@keyframes show { % L8 j$ u( j' H$ r from { 1 U& e5 F" P( L" k: X opacity: 1;' l4 N. F; U1 z top: 0; . V; `2 }. X4 j, V; u9 r5 W# Z } + A5 S+ S" T7 v! j+ f, v: _5 N% e6 P) ~( B( e; E( w, d1 y to {9 n X4 r& O& U# r! k$ s: A opacity: 0; |3 U% V3 F0 k1 d9 E5 z( O top: 100px; , D, a+ g* _, Z9 D$ Z } 7 F! W1 C% ^2 [6 f% G6 l} ) ?+ m# D* y- X' x - ]- w! z; r6 k' O' v1 U% Q4 y.message-success { 9 [. W9 z" S N c, Q! B background-color: rgba(77, 187, 41, .2);4 S; m& o) {% i# ? color: rgba(77, 187, 41, 1); : f$ Z/ m- F* ~# |* I- W/ s}$ { x# O" }! t( Q " Q; [' ^& L6 Z( b+ d6 x .message-info {! S3 h y* p) h# A( d background-color: rgb(144, 147, 153, .2);( U% a& v2 { \9 V" U. k5 D color: rgb(144, 147, 153, 1); 3 I V: `, M0 L: Z r} + r* m" B7 s, B# B 5 {; J" l+ f2 z8 J" A.message-warning {+ v2 D, r! l" U! y2 Y background-color: rgb(230, 162, 60, .2);" c, C( C' V! u% s/ U9 N* G3 d9 D color: rgb(230, 162, 60, 1);4 E+ W$ p6 n6 g' a' t/ Y# |2 f( L }. V) v* ?! a2 J 6 c5 C* @7 Z! N, Z/ _/ B1 j* O .message-error {% J5 D0 K2 T7 t9 b background-color: rgb(245, 108, 108, .2); / W5 d' ^4 y# x+ |3 }- G color: rgb(245, 108, 108, 1); 1 U |3 v/ m4 i$ G% z, c}2 O4 p' x( P2 m2 J' j% ~1 A+ [0 j $ F; F; W8 O1 s6 E7 ~ + v. V5 Y" P/ f$ u% ^{#if show} m! x+ z. W$ c3 w, y2 P; B: ~2 v' v

- i: X( l5 n! F) t! i0 A{/if}

Tooltip.svelte , U( M0 f0 g- e1 `8 A9 R export let content, tooltip;( Q7 c8 Z1 z# {9 l ! `' q$ o3 \0 \9 R 2 g! g: H+ e3 l8 Y 5 g. f, v+ `$ b# Y* i+ h/ e. ?. _; @ % Z' b% r; ?9 h7 c .tooltip { % w9 A* u" {6 h; } position: relative; 9 E* \7 U3 P' {( f s} 5 V+ d. p# e- Q0 B# u) N ) d# y% p0 b( L$ f3 v+ h- B. V.tooltip .tip-container {- d# d+ Y$ V+ E$ K position: absolute;5 N6 F" N h n8 G background: #666;4 [+ J% [) Y2 J( | padding: 0 10px;& U' D( ~1 a3 ~ border-radius: 4px; B0 U* `) p* f# J, V4 `$ r: D right: -180px;2 N2 \: M$ h. S) O9 x: P top: 50%; + |, `7 V1 q( e; L* q% ^ q6 s& i margin-top: -24px; 4 x. F9 `0 O: y$ ]}* ?2 ]- J c6 @4 u9 Q ! [9 m+ n/ R% K2 s$ j% I .tip-container .tip-triple { : R. z& t$ }2 k' o! {' n1 p width: 0; $ j5 R& S/ l8 q/ |. \: n' z5 t height: 0;; }1 s2 o0 g/ a+ ~9 I9 @ border: 8px solid transparent;' q/ a8 M( q# o1 q! Z9 d2 D border-right-color: #666;; _4 X2 w1 y- c% S1 [ position: absolute; . H2 ]1 o! P. @$ T1 c W& b5 J left: -16px;8 \- c) R3 `$ w! C9 `% q3 | top: 16px;3 v7 X+ p" P# `) u2 \0 S3 i: \; ^ }; P7 z( n2 m2 Y8 B0 ~! y6 q3 J ( w5 P4 r s2 } .tip-container .tip-content {/ B5 i. I! p) Q( x- Q+ K: | line-height: 24px;% u# \/ D/ |; w# ~' R& M font-size: 12px;8 u4 v1 U& `/ r, K6 N1 y5 ~1 q color: white; + f2 [4 @% S/ n1 l, O}6 p: N7 L1 l! i & U2 @6 [% r3 o# @1 W* C) f& ^; e+ ?2 O2 r' x) L- E- [3 P$ H$ S

) X3 X" Y* F0 F: d/ O% f6 g6 [ ; Q9 `6 ]* [ R4 V {#if tooltip} 4 r* }! R- l' k* ^7 f6 ~$ Y
0 T. q! t3 U' F2 K5 I) {8 {2 p4 v' J' v , Q+ n+ u& ~/ D& S, W; s

{content}

7 Q8 n: d8 {: h3 `
& I( `3 [+ E, a. w) V( y' r {/if}0 a2 m) b9 D$ q3 G

Upload.svelte - Y3 |: N3 e' q; }" ]% h+ s# L export let action, onSuccess, beforeUpload, id; - ]7 F2 |+ \3 z& u$ C( _# ^/ ` function ajax(options) { % X! j y3 q+ P+ c const xhr = new XMLHttpRequest();& Q- `4 l) ]6 X5 H const action = options.action; + m/ {6 W. B+ l$ n5 T let fd = new FormData(); 3 _0 c1 m$ v D! L3 p8 _+ M# _5 h* C fd.append(options.filename, options.file);3 W& A& [$ q2 K! ?- K- }4 ^( V 9 r1 {" J; [/ h( o; y xhr.onerror = function (err) {# K6 s" O- z. z% U/ F) |1 L5 H1 k) j console.error(err) + C( e3 y- w4 L4 ^; R7 U } / e9 y/ H" n* }4 {' O/ o7 H2 Q4 Y/ g/ N1 Z$ e" m xhr.onload = function() {5 s& Y- k8 M0 }! f const text = xhr.responseText || xhr.response;0 m6 ?! Q% v' A3 s4 m9 z$ t+ y. b console.log(text, text)$ `2 N! p4 l; F8 \! u4 \ text && options.success(JSON.parse(text))3 Z- f# y6 G, l+ o2 c- F } - P5 i2 I6 a2 q! Q- T2 r 5 C! S, T2 f+ M3 e: Q; I xhr.open(post, action, true);! ^: N4 Y: s% Z" Z7 A* K3 C' s/ r xhr.send(fd);0 p3 \, j/ ]7 n+ k- z$ O# o ) r4 s5 [4 c% ^9 [ return xhr;4 R7 v5 S3 R/ \; n }$ R! Z/ }2 ~6 F% |$ ^ function post(rawFile) { 7 W$ y; S* N* I+ C, }% a const options = {, ~6 ?# P2 \6 `) }1 k9 d id: id, 6 B/ J3 V! z* |+ L file: rawFile, # p" I$ B. T1 u$ h! S& b0 S filename: img,) C4 f2 a! a- ~/ m action: action,' p. }, A/ {# v9 b8 i success: res => onSuccess(res, rawFile, id). u' z! _$ G, M5 d+ ~ } 3 A: [2 \8 Y w: u const req = ajax(options);& ?' y5 T _ ?3 G; R if(req && req.then) { ( E/ }" h3 u% \& |; e/ ?" | req.then(options.onSuccess) - x1 J) P* g- x# ^ } , b! ]+ u4 u1 _* f } " q5 a, y# U7 k( G/ H \ async function handleChange(e) { 0 L3 j) A% _- l2 `' ]5 f const rawFile = e.target.files[0]; / o- X% b/ E7 o3 }3 a- z if(!beforeUpload) {. D3 z8 e. z( D8 q3 v return post(rawFile) ^& ^/ b2 I7 h! k } / u+ U2 ?. w& u* X1 c! m let flag = await beforeUpload(rawFile, id);; v, t! [1 |8 D4 s: @# [- s if(flag) post(rawFile)! O- Z2 l/ ^# w/ O } * V( ^, t& z: q) E! W! |8 j function handleClick() { 6 }% Y) D5 x7 |) j) Z) V, o+ N const plus = document.getElementById(id);* e+ Y7 j& S ]( e+ T plus.value = ; `1 l8 O7 P) m1 A. B) X plus.click() ( u* Q) S; ~$ K9 c4 C }" ?! r2 Q7 K3 g% d9 l" } ' i7 Q, O4 S6 t' A r + u0 j0 y7 U6 [5 Z: \) S 2 Q ` d8 x- } .upload {: `. Z4 Y4 B' q1 D! g/ f/ u width: 250px;, i- V V, N7 u" m2 Z4 t height: 250px; 7 {4 d! l; L$ q5 S border: 1px dashed #ececec;2 c7 m6 Z# ^1 }: ~4 q6 ^ text-align: center;- x6 Y& n; c7 T. s display: flex;. q* `- x9 P: W: a justify-content: center;0 a4 S: O) ]2 a5 m9 j* X# F5 l align-items: center;6 i% ]7 c/ T* Q& q {: D4 w9 u' ~ } 1 Z1 _1 |) r4 B$ I! _1 u5 \7 k1 V/ H5 }8 {1 r: ^ .upload:hover { ( l& c% V7 h! t( d cursor: pointer; 8 o7 ^$ l: J4 \, ?; i$ Z+ O }' ~1 c6 V M9 \4 E! `( F 8 o2 l# R! ^$ J8 C& Z .native-input { 8 J9 a- }9 k" c6 A* B4 Z display: none; + {6 V1 r$ G) @ }2 r( L) m- y$ c+ o S% X9 S( e6 Q + `* g6 O4 c$ K# i; n* V 3 Q, z$ D3 P, O' V5 M

utils通用工具库主要封装了图片及函数式编程需要用到的一些工具函数function.jsexportconstcurry=(fn,arr=[])=>(...args)=>(arg=>arg.length

===fn.length?fn(...arg):curry(fn,arg))([...arr,...args]);exportconstcompose=(...args)=>args.reduce((prev

,current)=>(...values)=>prev(current(...values)));image.jsexportconstgetBase64=file=>{constreader=new

FileReader();reader.readAsDataURL(file);returnnewPromise((resolve)=>{reader.onload=()=>{resolve(reader

.result);};});};exportconstgetPixel=img=>{constimage=newImage();image.src=img;returnnewPromise((resolve

)=>{image.onload=()=>{constwidth=image.width;constheight=image.height;resolve({width,height});};});}App.svelte

, ?8 P# V; T: l$ p" Z0 J( o import Icon from ./components/Icon.svelte; - ]- e9 p% E. P% B6 c+ R9 N+ [' O import Button from ./components/Button.svelte;7 p9 P# y5 G. Y$ _: S import Upload from ./components/Upload.svelte;' k' n8 ~& t& C" y: _ import Input from ./components/Input.svelte; : D$ `- j4 P' \9 p8 B e import Message from ./components/Message.svelte;: J7 m( m( }, B6 X/ l! v- F; h; z import Tooltip from ./components/Tooltip.svelte; ) J/ X- a# P) f0 J2 V import axios from axios;$ P y6 r5 V$ Q% K& {: S" r$ E import { getBase64, getPixel } from ./utils; & J6 Z! j8 x/ f0 r& Z, o1 ] z0 p7 J' [+ @. ~( k) V8 X/ Y7 L2 h const bgUrl = ./bg.jpeg,: [' b, [$ ]( A. I3 V- I logoUrl = ./favicon.png,; C3 r/ @ _" U! \1 E% Z! E actionUrl = , . G+ I# k1 h& T% B$ ^* }8 h compareUrl = ,7 \' s8 R/ v1 s: `1 p$ E downloadUrl = , " n8 n6 j v1 |7 j j) l crxUrl = ;: I; Q2 L( g" e7 p; d0 t let width = 0, height = 0, flag, compareName, errorMsg, successMsg, show, tooltip;7 q8 L& J5 w9 y5 X4 |; o let uploaders = [ + O3 |: z- B7 s T2 Y3 s { 4 N1 N5 U9 [$ _% Z6 r2 A, L1 R id: design, ; L6 J+ k( ~0 r% H( m title: 设计图, ; |: R& w' ^9 K0 X filename: ,) V. F9 e- ^7 S1 r3 @ J; t url: 5 b8 S @; T7 }5 C o },, c; C) f8 k3 C, ~' |% z {8 i( g J0 E" l" ~ id: code,6 `; [9 v6 ^) \& v3 T title: 实现图, ) i$ n8 u* e$ X+ Y0 W+ `3 x filename: , {% |* Z: b, |5 z1 k url: " T1 W# B8 h7 ` }! `, O$ ^1 G0 n+ ?; m# { ];+ G8 r$ P0 N% W& u0 e0 z# x( k; u0 \ 3 L: M. S& G5 e const handleCompare = () => {6 l: z! m/ w; K& V8 | show = false; / Z# s3 _& `+ z* w" B8 m/ ?; v' b const len = uploaders.filter(f => !!f.filename).length;* G0 N" a% \9 s3 u if(len == 2) { ; {1 O' y! M% N$ U. K& W8 \8 I axios.post(compareUrl, { 7 c) |/ k& I2 r% x designName: uploaders[0][filename],4 J9 G2 Q& }/ h C% r codeName: uploaders[1][filename],3 O s' b; g! ^% ] }).then(res => { 8 {/ p5 f3 w' @& D+ D3 P console.log(compare, res): Z1 A7 `* t* M. s p if(res.data.success) { + E G Z5 j9 x$ v) B: ~& K0 T) l compareName = res.data.data.compareName;4 z7 v" Z3 a* {6 w: Z, O! N) p. `! V return true: ?! b ^" w" Y( Q5 t2 w } else {/ A; x- @0 X! }; w( K9 G; Y flag = error; e+ Y+ n/ }8 O P show = true;, i) f2 ~5 A3 ]0 U6 J5 V errorMsg = res.data.data. [: M: C% v# c } 7 X3 W* l. D% E }).then(c => { 1 |% i4 n) D% W+ N" m' A3 W if(c) {" ], i/ y8 T" e" _ flag = success;) C! z3 N% j+ C7 `3 Y& o3 ~ successMsg = 对比成功;6 N5 g$ y- }: J# K+ ?9 \" F% ] show = true; - K2 H( p9 T* ^) O% D handleDownload()4 N$ ~+ }/ S. y& Z handleDelete()5 p4 F$ {8 f/ V; E. i }. F9 t2 y; f! \- ~ }) * G: T k7 X. e" k+ ]% E } else if(len == 1) { + Z# v, H" m8 f window.alert(设计图或开发图缺少,请确认已全部上传后再进行比较!)( @% |2 t: a- P1 r7 C% |6 L0 ? } else { + l6 E: G- M3 c9 b window.alert(必须有图片才能进行比较!)- [; Y7 G2 M. j& {6 x6 q } ' L' Q, {( n( G9 b/ F0 z }; * i# _# E5 B! U. G. A , g: u$ O( Q: N. t7 a const handleBeforeUpload = async function(rawFile, id) {* }9 @- Q* q" I const fileBase64 = await getBase64(rawFile);& K4 s. U0 d" d9 O+ o5 i const res = await getPixel(fileBase64);* O7 H- X. ]# C // console.log(res, res) ; [: l% }9 b0 B9 z4 y8 F" E if(res.width == width && res.height == height) { ! {, e9 S0 C4 j; t% x& B# ] switch (id) {2 S! E* K1 \7 B& B* B$ q case design:7 |. F4 _2 r1 e; C uploaders[0][url] = fileBase64* D& Z/ ^6 n$ J4 E+ @) q" j9 A break;+ ?" y( c; `( j0 v$ T& |6 O case code:+ N: K8 X: q# ^- b uploaders[1][url] = fileBase64 ! u% f# g% W9 T( O" H break;! R3 ?6 p$ N" x, n2 m' o2 G: H: _ default:: @' D2 q, h: `" x8 t# _ break; ) B: K, f# T' T* M+ M }4 s% O5 B8 Y- f# r6 @' B7 k- o: x4 M return true; % e3 c+ L6 d5 ]+ I/ W j. a } else { $ w6 n5 Y& ]. r window.alert(上传图片不符合分比率要求); ; ~. M1 U, [ `8 g( @ return false; $ T/ ]' j& ~: j; V8 f/ a }: L5 i B' @9 Q. p) O- f5 l, A1 S2 h }- S+ Q% |0 ?* X/ P, G1 k$ _ - w! @0 b1 x: S9 J, m const handleSuccess = (response, rawFile, id) => {! y( [- U8 t6 t* D. l: V: |2 h console.log(response, response, rawFile, id); % Y, W& E9 S. o% \& E5 i9 Q* i if(response.success) {1 f' u& w9 c6 V) [1 V8 ~2 P switch (id) {6 [& y1 v+ c* _) e- c4 I case design: a; i3 T8 O6 S. J. m uploaders[0][filename] = response.data.filename6 ]8 g% f2 k/ n! F) z break; g d7 [; y$ k' t+ O. b; O case code:2 N0 B! J# ]- I# O" c1 K uploaders[1][filename] = response.data.filename3 h2 C l, o% T break; ) f2 ~9 W8 Y L! E; _( Y; n default: h7 H# ?* n- ?( X8 W! N break; 9 N3 u% i P, O* N! k/ e- O } 1 K6 @1 ^4 [4 ~- O7 ?- y- i, D } 3 I; O( b$ B! ~: \1 j7 G } 4 W6 I" a, T7 c$ Q1 C- l0 Q) n) x & e- @0 w) V5 {; F* s6 T3 R: v- o function handleDownload() { ' z- V' l8 ^, h( D. ^ axios({8 e; V2 Y3 |% ]& q8 E+ ? method: POST, r9 b4 E2 D+ {% d$ B url: downloadUrl, * C0 x' H6 a9 u5 a, B8 c responseType: blob,. L: h. a: c5 i, } data: { 5 T0 Z; y4 F% R compareName: compareName ( d. p4 p+ G# z* L2 g5 Z$ T6 f } 6 E ^4 l9 b' [& |0 I }).then(res => { 0 h7 Y9 P8 a) L3 T console.log(download, res) G1 _- m9 c' l' L if(res.status == 200) { ( }6 Q# L# T: p7 c+ `* q var blob = new Blob([res.data]);5 \! f A8 \: Y+ m" J8 ? // 创建一个URL对象 / q d# }$ ?: [+ `& Q9 n; Y var url = window.URL.createObjectURL(blob);3 Q w( X# _5 Y% t, { C console.log(url, url) + v& e1 W) M3 }$ C' ] // 创建一个a标签+ i- v Z- ^& e2 \& I& N% B; n0 t var a = document.createElement("a");" N1 W' i# v6 M" B+ N a.href = url; # c# l$ s; N- _% F4 Q2 p* G n a.download = compareName;// 这里指定下载文件的文件名$ n+ `, F) Q( w+ D/ Y- b a.click(); 4 Q# D! g; V" P" t9 i7 [ // 释放之前创建的URL对象 ' j- d) @% |/ p window.URL.revokeObjectURL(url); 0 B* q) _2 `, ~/ `4 Q } ( \1 Q: L* j; s# L; w- }9 c( M })* G a+ ]. i& I; I$ B; Z3 m } * J5 ?* M# X) ]. Y. a) t4 }& U) e/ [ c. j" a( \ function handleDelete() {9 V8 j5 x% O9 \/ p6 ` uploaders = [ ; {5 I; f8 a$ j0 B0 r& j {: F, {5 T P. U( D5 ]6 h id: design,/ H) g; B/ q0 o2 k' M$ G title: 设计图,8 {, g6 I: N/ x9 @ filename: ,' `( f, i w1 S( | U, N' N url: 6 w( O2 i5 M9 R; s3 |) i% r },: f$ }' l# U3 Q" {2 i* i. y {. Q0 d3 o6 e! L1 Z; O f) M3 ` id: code,( d9 W6 K" a- ^1 R title: 实现图,7 N6 P/ j7 k. ^- _% o m! F filename: , 2 A0 I. x6 h9 t; M6 ]' O url: 7 m. B0 D/ ]/ J) j: e. [8 _ }- s3 m% p; x9 W7 C0 h6 ~! w ];* m0 P5 ]( Q2 {) x9 n } / Y% {/ n( ~# g( ^: X. E f# y8 {+ m4 L3 M: x% N + t8 B8 {4 F N( K , |/ s( c; T+ O- E, Q+ S .pixel-piper { % c3 e! l5 W1 m* f7 Y# R5 _ ` width: 100%; 2 r+ L! M5 R, Z height: 100%;/ `5 a7 ^, F* s% H# S4 T display: flex;' {2 h8 B5 e% h* h6 P& W: |$ w justify-content: center;/ U4 `1 ~# c* } v align-items: center; # |0 i8 |& o7 E }9 i7 O! ?5 \+ I% S# N6 ^* T$ v 2 ]$ Z; E6 n) ?5 O- [. \, k0 v .main {4 t; p6 Q6 k8 i3 O+ F) }5 x width: 600px; 5 O) q0 f, S+ }( K9 u1 _) ^( I margin: 0 auto;8 x4 r3 T1 G9 m- {9 X padding: 20px; " T* O* J' d8 s+ ~ ? j border: 1px solid #eee;' j2 H1 R4 o* @5 B background-color: #fff; + F$ c' v5 D2 ]1 x& c: K. u border-radius: 4px;3 g7 }$ R1 Y( Q4 f0 L& } box-shadow: 0 0 10px #e0e0e0;/ h9 o8 U* Y( Z# C8 G } ! ?9 u: {5 i5 G" c2 W, w! H4 i * D& }$ O n5 d7 z .main .logo-container {6 N5 x6 w: F% T& d; w, W5 d display: flex;% h7 A& W$ Y# z: A5 ]2 x justify-content: center; 5 ~1 G) ?& G+ `0 W align-items: center; x8 s2 U! u1 n& F" i, r: Y0 g } ] l( m; d4 }( m' O: W ( w0 L; T/ c' e8 m; R( M2 W .logo-container .logo:hover {4 l& Y$ D/ l5 _" k# h6 i* g' T* A% X opacity: 90%;( Y+ k0 W- S4 f- K cursor: pointer;0 k; V( @/ b! i( b- a }1 S( ?- G P$ {' S, D 3 Z' T# ~2 B2 ^# t* c .main .select-container {6 l4 N) `; |# F: w" f display: flex; & _, x$ o2 g; H2 F, l9 ~, X align-items: center; - [% [ V, B% q: a align-content: center; }2 j: v+ `/ F2 [ justify-content: center;0 g; Y0 O% ~4 W9 G justify-items: center; 3 R0 W3 Y% {& E! q% @. L line-height: 40px; 5 }3 _5 P% r$ w' m }! d# W8 E3 A+ b1 {4 A) j0 ? 3 G7 E Z* ^& a9 _. K .main .upload-container { 0 I# r4 D" e6 p+ u display: flex; * P. `' d+ B5 a- ^+ B0 @, h padding: 0 0 10px 0; ) q9 ` k7 [% D4 j5 S8 k7 d0 O justify-content: space-between;5 t% ]# X/ d2 b) X' x text-align: center;% B+ O. @; v# D } - p! O' {2 U8 y; A) Q& Y- g8 B' X( I' B6 C& d0 N9 N .main .button-container { + Z# ^* y2 {1 \9 J display: flex;+ U7 V" c* I& s [1 u) Z justify-content: center; 4 k' F7 n; `! o) _8 c align-items: center; 7 i6 J: ^# @# e9 _) t+ G: z) g } 1 U6 H* B' C/ J/ p$ f 0 p: T% k0 f5 o .main .info-container {+ b1 D p. k+ D text-align: center; 7 p/ J- K( X$ H! c6 }- W color: red;; ^0 s8 e( ]3 q* V font-size: 12px;) K% _4 S. c. p4 F; j/ W9 b9 { margin: 10px 0; 7 ?0 n( f( s% p! U8 J$ G } & P9 ~* q- A& v0 ^: O) a0 K# J9 D- p+ r& e 4 @+ e; o1 b! n" l! r; G

. p; \" p8 b; D& K) D2 j F7 v: Y6 I$ U0 D7 b
1 m( [5 B7 Q+ D4 Y+ r7 b2 i3 m9 u ) P% g5 I# d6 k, s0 A1 T, K" U4 s# A - |$ V0 Q7 I# p0 w$ e tooltip=true} 6 F8 G' W/ R! I9 H% h4 c n# e on:mouseleave={() => tooltip=false} ; @1 D# E) N9 B( p' p M% ? ># N( d4 ~5 P" c. ^5 [5 f: |) ] 1 Z$ Y- {( b# _ 3 h4 ]. ^' }) n+ S7 C, [7 h7 k
R! G) H! F4 o
E- r- w& m& `2 K: I" V5 m

x

) L0 B+ z8 _! X7 ^
4 `- m! F! ~. Y9 }6 H' @
3 X' }1 ~% B/ ~0 J; b! [- D {#each uploaders as uploader} ( g! b, ?5 V$ o& q
- X( r1 Y2 Q/ P& n 6 S' z- m1 B* a5 D! m" _ {#if !uploader.url}" K8 s% j3 J. a1 B . X; p8 h; ?/ g# } {:else}* d; n F% E5 y F$ [ 0 [" Q% Y2 M! Q: V: M {/if}1 @# v8 N9 A2 O$ t # t: y" P* `) L' J {uploader.title} 6 s- _2 Q: e! i
# J% [, W$ \. B2 B3 \1 T. w {/each}: H* ~ p0 ?: [+ b
1 Z! V0 A# E: S- {2 u1 P+ J; [6 J0 L
' p8 w) Q( C$ f% [) V7 D {#if uploaders.filter(f => !!f.filename).length == 2}+ @4 Y1 m) Y8 r Q3 c 注:请在两分钟内进行图片对比!!& C# L& a2 L H2 a' I* f {/if}& ^# {1 w& `# k0 H+ q" }1 q
% R |) T+ g3 a0 n$ n2 C
! p2 h ^& t1 K8 y: [+ ?" h 对比 ! v" q$ Z% S3 F: U* O {#if uploaders.filter(f => !!f.filename).length == 2}( a9 h0 a4 I8 v# w& W) V9 x
1 z: Q5 f; k) w 清除图片9 s" ^9 G" s' y& L, Q
; e8 g3 d q9 V# D: V {/if}2 O, p" ~5 w/ ?+ v) H1 c
. s# e A/ u: Q ) i5 Z: ~# H- E% z# b {#if flag == success} 0 K/ U; G1 k3 [7 b$ } {successMsg}- j" v- r* d$ H/ a T {:else if flag == error}, j$ k; c! W k1 B) E {errorMsg} * ^; F* P8 O4 ^! A# L {/if}3 G) [3 V9 ]3 s% A' x7 H( a+ R

总结作为前端工程师,我们是距离用户侧最近的研发同学,不仅仅在于完成业务的代码实现,而且不同于其他研发同学,我们也承担着产品用户体验的重要职责,而这其中页面的还原程度是一项重要的指标,能够让设计同学认可我们完成的工作也是评价大家前端能力的一个维度,毕竟上下游通力合作,才能把产品体验做到最佳,共勉!!!

参考Svelte 中文文档一文详解 Svelte干货 | 携程机票前端Svelte生产实践Svelte 原理浅析与评测新兴前端框架 Svelte 从入门到原理被称为“三大框架”替代方案,Svelte如何简化Web开发工作

设计小姐姐都说好的视觉还原对比利器使用Svelte开发Chrome ExtensionChrome插件manifest.json文件详解30分钟开发一款抓取网站图片资源的浏览器插件一天学会Chrome插件开发

回复

使用道具 举报

    您需要登录后才可以回帖 登录 | 加入怎通

    本版积分规则

    QQ|手机版|小黑屋|网站地图|真牛社区 ( 苏ICP备2023040716号-2 )

    GMT+8, 2026-4-4 06:53 , Processed in 0.059375 second(s), 23 queries , Gzip On.

    免责声明:本站信息来自互联网,本站不对其内容真实性负责,如有侵权等情况请联系420897364#qq.com(把#换成@)删除。

    Powered by Discuz! X3.5

    快速回复 返回顶部 返回列表