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

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

[复制链接]
我来看看 发表于 2023-03-19 07:13:29 | 显示全部楼层 |阅读模式
1 v% f. Q+ j; f8 v" ^( S( h

项目背景

0 _ q; G/ Y$ C

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

" h& |' A4 l* B V

方案

) h1 c5 e1 X* T% x& a+ f% q: T

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

0 J- b$ O5 l; v7 C

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

2 h, U+ E: v* s# S! N

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

- x- e7 k9 f' J. e- K( ]. `

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

\% c# z/ J3 g0 P2 V# z

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

4 ?. b1 ^" B2 U6 N+ M& _! E

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

: D( H* E& @6 A" _: t

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

, u( E% `$ o" Z/ y

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

9 w: r3 J8 e, V+ x) h/ h

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

2 `5 b+ N2 Z" v" ]4 Z. A

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

& b/ p# W7 Y; d2 z! ]( A+ o

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

+ S4 {; s Y" y( o3 `2 \# @: [

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

" I+ y. L1 G9 T

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

d5 V& F3 V# I* D, A

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

$ T5 J% `0 N( F8 N# A7 u# n

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

( H7 B. f& ]8 N& f

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

/ A9 R3 d) E( j$ ?& q$ F

,format:iife,name:app,file:public/build/bundle.js},plugins:[svelte({compilerOptions:{// enable run-time checks when not in production$ M5 I- e9 @9 ?8 S0 l, @1 B

; a) {" @+ U" s# i& z" w5 F" I

dev:!production}}),// well extract any component CSS out into 9 |; P4 r! O. Z& C, v5 n: T // a separate file - better for performance% R( ?5 X0 k' b

/ G" ` ]: V- E6 C; u$ _6 l0 u( V. D

css({output:bundle.css}),// If you have external dependencies installed from . _% m r* c/ `9 ?- p2 A+ [ // npm, youll most likely need these plugins. In % Y, b; p% s3 S/ l% F$ @

0 U# N6 E9 h$ s; @

// some cases youll need additional configuration -+ z( f; ~& j$ P: C8 y% B // consult the documentation for details: 5 m( C9 x% o2 U* j // https://github.com/rollup/plugins/tree/master/packages/commonjs " M+ {" h1 _+ Q% [3 H# f

: V) M. E! m" |# m, |# f4 w8 u

resolve({browser:true,dedupe:[svelte]}),commonjs(),// In dev mode, call `npm run start` once8 ~0 a: W# R, T t6 `+ g# d // the bundle has been generated0 @$ l3 ?# x4 T0 S

3 ]5 _# L9 X8 d7 W( b$ Q

!production&&serve(),// Watch the `public` directory and refresh the5 Q' z) }# W* u7 K% s# K, v+ S // browser on changes when not in production/ ?* O% @% Q/ R9 J

5 s5 e5 j) ]8 K4 E: {0 a

!production&&livereload(public),// If were building for production (npm run build" @9 B# v$ K! J& C1 f // instead of npm run dev), minify' t4 T m- a+ f, E) `7 I2 C

8 T$ S' I- w: j* T" N8 {! M

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

8 o9 T- y) C, d; |7 A' X

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

7 l' l& N) J/ p

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

$ P: t9 i. G8 k+ v

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

0 @0 v0 b! u7 ]0 r( b! U3 x0 m

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

4 ~% t6 G4 |% ]

);// 压缩完成后向 cdn 中传递压缩包 2 [+ V- R/ I9 S, d5 J8 ?5 h constfile=path.resolve(__dirname,../pixelpiper.zip);fs.stat(file,function(error

2 b+ f0 h" _2 q" [5 [5 w' z* }

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

2 ?/ q: W: ]# O7 z. {4 y$ |

),stats.size,application/zip,function(err,etag){returnconsole.log(err,etag)// err should be null . O$ S, S0 J. N1 [" W })})

4 H# \3 t* Z0 j# a. g: ^7 V0 C

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

/ F2 I8 `( G7 _6 O! l0 ]/ \

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

% b o2 Q3 _5 ^0 P4 K. Y7 u/ \

);archive.directory(path.resolve(__dirname,../public),false);archive.finalize();setupTypeScript.js// @ts-check4 C2 p2 h8 X6 g, v+ |( t7 U3 N& ?

7 Q) Z, x* n" C: `

/** This script modifies the project to support TS code in .svelte files like:- Q" v) V } }, H1 d , m) s0 E* X5 V: V export let name: string;- f* I' P" {# K% g( n

j* W2 Q. i o

1 K# w4 W" ^- y9 o) U& `2 ^5 G/ c As well as validating the code for CI. i' I" M+ U* i0 h *//** To work on this script:' O/ U& m" J- y3 C$ R rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template* {7 k6 X( V8 `

+ @9 B* I" L& ?) G3 n& K

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

- C# S. f* c! C( g4 O

]||path.join(__dirname,"..")// Add deps to pkg.json x! v1 t- ?$ D constpackageJSON=JSON.parse(fs.readFileSync(path.

; h* n. @% `5 @+ p

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

" S B+ [# r. f& [, W

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

9 a6 m- U) T! `) e" b# }; X8 W

:"^4.0.0","tslib":"^2.0.0","@tsconfig/svelte":"^1.0.0"})// Add script for checking( R' D1 Q- D; h4 O) G$ O3 S! E* ] packageJSON.scripts

) s2 q! k0 Y' _3 A' h

=Object.assign(packageJSON.scripts,{"validate":"svelte-check"})// Write the package JSON' k0 I5 N( @0 W5 X4 Z- T0 o fs.writeFileSync

2 u* n/ ]( |7 O) j; s4 n8 b1 M

(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 9 E7 o- u% a6 Z! T

/ ]3 U3 M) H4 r2 z- l& G, |

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

6 C+ E6 g! [7 T: d

,"src","main.ts")fs.renameSync(beforeMainJSPath,afterMainTSPath)// Switch the app.svelte file to use TS 4 M. a( Z F$ ~% `& }7 a

" q( p+ y0 n4 U+ n

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

! O9 i+ }# c, C4 J" V8 e$ w

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

# Y) a' [" W* v4 m

,export let name: string;)fs.writeFileSync(appSveltePath,appFile)// Edit rollup config/ w- l/ f/ v7 A' f constrollupConfigPath

+ T( G- x- R7 d( e

=path.join(projectRoot,"rollup.config.js")letrollupConfig=fs.readFileSync(rollupConfigPath,"utf8")// Edit imports) B3 S* @2 W% ^

3 A4 Z9 B. z' q- P8 i7 V5 h% f

rollupConfig=rollupConfig.replace(`rollup-plugin-terser;`,`rollup-plugin-terser;# l0 L8 e+ O! s X) G* E9 F5 v) } import sveltePreprocess from svelte-preprocess;: T7 B* L- a% u* L" |: X# _

0 P; w* }; i0 C% d" s; ]) @/ W

import typescript from @rollup/plugin-typescript;`)// Replace name of entry point * w* u5 ~3 I& B9 M3 i2 Q rollupConfig=rollupConfig

$ ]6 J- h; c" x- x* B

.replace(`src/main.js`,`src/main.ts`)// Add preprocessor, D: K t* K4 r( Z/ w( _ rollupConfig=rollupConfig.replace(compilerOptions:

, |; f( J0 O2 p' h6 P t) \" F

,preprocess: sveltePreprocess({ sourceMap: !production }),\n\t\t\tcompilerOptions:);// Add TypeScript; Q- `! N% ~ Y- L) E/ j

: \* t0 q% \+ C8 ^% ]- S$ u5 F J

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

. x. o9 L/ Y) o2 N7 a- K

);fs.writeFileSync(rollupConfigPath,rollupConfig)// Add TSConfig 1 H; h* y# l7 t* z& [( g/ Z consttsconfig=`{0 K' W0 c+ V/ z' s- I1 ? "extends": "@tsconfig/svelte/tsconfig.json",6 W6 Q+ p* T4 q' ~3 }8 r

; ~) Q+ ?, m3 H( z1 ~

"include": ["src/**/*"], " z2 f6 o4 y5 ]6 e# s# K "exclude": ["node_modules/*", "__sapper__/*", "public/*"]! W. [% y" ?1 n! e( i }`consttsconfigPath

+ T6 r! b0 {; R& _; D9 Z

=path.join(projectRoot,"tsconfig.json")fs.writeFileSync(tsconfigPath,tsconfig)// Delete this script, but not during testing * I9 T( F8 J# V9 Z0 W/ d `

8 M/ ^7 e# A+ c- G( j

if(!argv[2]){// Remove the script + _* k8 G$ W& Z8 n' g2 w$ ?% O! z- s fs.unlinkSync(path.join(__filename))// Check for Macs DS_store file, and if its the only one left remove it , V- {1 |8 ~; v4 D' C

( M( a3 |& B0 P a' D

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

+ p8 a: ]& M* _ p: N

0]===.DS_store){fs.unlinkSync(path.join(__dirname,.DS_store))}// Check if the scripts folder is empty! X! s! g' x! k3 N5 |5 _

3 _7 ~9 a0 C- H9 \* I: T

if(fs.readdirSync(path.join(__dirname)).length===0){// Remove the scripts folder $ s/ z- V7 U; ]7 ]0 @1 ?) y8 ~/ y fs.rmdirSync(path.join

9 w @* d6 {4 x2 I" g# G$ Z

(__dirname))}}// Adds the extension recommendation 4 n3 V) m! f7 @% q2 I fs.mkdirSync(path.join(projectRoot,".vscode"),{recursive

6 `& b2 m9 S( w5 }4 z) ]

:true})fs.writeFileSync(path.join(projectRoot,".vscode","extensions.json"),`{ - P7 q) C! H+ W "recommendations": ["svelte.svelte-vscode"]+ L* x; N) [6 F# m9 y8 ] T

0 R6 J9 y6 d0 a

} + n* ?# i' H/ ?& A8 n* U9 N `)console.log("Converted to TypeScript.")if(fs.existsSync(path.join(projectRoot,"node_modules"))){console

& }2 S. \- a- R

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

" u2 n' }# C3 J( _7 U

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

+ e. D9 k- ~6 P/ i

、 Upload(上传) 几个组件Button.svelte 6 q7 f$ w* s9 d* N import Icon from ./Icon.svelte;; |+ }. P" a0 [ import { createEventDispatcher } from svelte; ) S" U: Z/ d0 m) x" R- a const dispatch = createEventDispatcher();5 _" g& K+ B2 ^. ]4 r* K export let icon, type=default;& Y- z S: V& \) W5 {/ e function handleClick() { " |5 i6 Y: F8 N0 l1 k, T2 Z dispatch(click)* }# V3 ]0 X+ Z' ?3 S }( U3 N- V+ a( X7 M4 O2 D function computedButtonClass(type) { 0 t* O2 c* Q% a$ D- J4 t; K- L switch (type) { 8 E. L! D6 v7 [4 n& O case primary:# _& D: u S- w Z( z; n W return button button-primary; * U, V J. H! S# g) W- W" J case default:; d# c) z: n) y3 l+ e return button button-default; 2 I9 s# L Q7 L1 v case text:6 J7 N+ v/ {- Q return button button-text; & d( K2 Y; L3 K A default:" q! S! j% L. h, `$ _- } return button button-default; k0 C) l3 p4 g5 D$ y7 A) f } ' A, Y8 t6 ^7 M& S6 [1 f }, V1 [* a" s3 C$ N" ^' n$ l . j9 I4 T/ x# j4 P' I- T) c7 k 8 C- ]3 V; D) J* V/ ^% P3 N) Y ; v" l, K9 b6 G7 E .button {" b& X4 |3 |0 k$ h border: 0;" k2 @* d9 P1 h5 m- P border-radius: 2px; : C8 E! \* I) I* ]7 ?' q1 W: N }( s4 E; Y6 `. r9 I! z. V" Y 3 P1 u; c+ H+ W .button:hover { ! @# ]" i* M6 o4 }5 l cursor: pointer;! K2 V$ U4 _$ \( W } 7 u# }) J+ F* x; Y6 x" H) ^8 h. m) g" t8 ~ .button-primary {4 Z* S: M6 a' g* g. O( O6 _) g background-color: rgb(77, 187, 41, 1); * G& I P1 S- d' `$ O6 r. D! V color: white; : r4 J0 C+ w) [) `' @- G) M N& I border: 1px solid rgb(77, 187, 41, 1);6 u9 F0 E- B9 j! j% Y9 y } " V" C8 P' ]4 m+ w) q/ X4 M' q ( j8 A/ [0 p Q- x9 j9 f2 g2 U .button-primary:hover { & a2 Q5 @: X4 Y8 M background-color: rgba(77, 187, 41,.8); 1 @+ m( M* H ^- v: K4 z( Z+ D } 4 q- k! _6 T: s1 b( L4 t \1 E" B0 a" i .button-default { ) @; h& q- w/ V- w P' i background-color: white;0 f" |. A8 g0 i) m) M' A# Z color: #999; / l# K+ }) A) b$ _, m: Q6 p5 A1 E% ~ border: 1px solid #e0e0e0;9 O' p5 |) B! ?- m8 Y1 A } * s6 ~( j. C- R3 `8 l6 a0 q' G8 ]" P- K: I+ F) `- ?7 ^ .button-default:hover {" H; Y+ U; ]% R! r background-color: rgba(77, 187, 41,.1);' R9 I8 r6 D' k color: rgba(77, 187, 41,.6); 3 }4 [1 `( U& C/ y border: 1px solid #e0e0e0;# F1 X" x) I0 B } 9 E4 k$ J' R. k J3 S9 O- o8 i9 s1 K5 }0 I4 I4 ] .button-text { 5 [0 l! _6 ]$ j2 { background-color: transparent;% |( \' j! B. ?7 z+ M8 f% ^ border: none; * [ o! w" p" j0 E9 u; Z }# H/ g+ C* v: k* u0 ]5 A9 R/ y: j" P * }$ Z. {& W% L2 L3 ^* X0 r$ } " R, G' o' B. u; D. M8 Z 8 I! |) o/ z: F" x& e9 M {#if icon} / @" G* ^! B' U/ {, F% l , [% y+ j7 \+ |: u3 x8 Y {/if} + o k1 d K1 O& ]! { & q: J I2 }0 A7 ^* _0 }# V

Dialog.svelte 5 ~" K. u/ Q4 l0 ?" s& c9 Uimport Icon from "./Icon.svelte"; / t8 z% d4 k# _, a2 @5 L. Bimport Button from "./Button.svelte";& H0 r$ _' u. V3 m/ w8 _6 f* O import { createEventDispatcher } from svelte; $ f9 Y% d; e7 O5 X; ] p( @+ {const dispatch = createEventDispatcher();) I( ^) I( U% W$ }) o, d2 n& r8 F export let title, visible = false;1 F6 M' w3 {6 T8 M3 L$ o function handleClose() {+ e9 D7 M' T2 q. ^& t visible = false;2 ]3 Q: F0 ^8 v1 T; a' c }4 A; v ]3 O' l. x! A6 U function handleShade() { ) u- R1 A& o) ?$ v1 u visible = false; 6 ]0 u1 P* \; z2 q} 3 f; P# U0 }. A. N" ^# {function handleCancel() { $ c7 r- [% t6 |, g$ T: H) q& K visible = false;5 O/ j7 p5 T d$ c# K: o- Q( _" O. p9 Y' n } 9 p; C9 E; E( Z/ W# X$ Xfunction handleSubmit() { X( t8 }+ J4 Q8 {) { dispatch(submit) # V2 [+ W1 s8 }/ L$ f9 R; s} " i# h# O" o6 H0 }, ] ; [ E9 h2 s0 h- Y" Y+ j 9 I, ~. e, F& w( K0 D7 K' H1 B9 Z7 E6 v" n) I .dialog-wrapper { 0 Z! d% f/ W4 B width: 100vw; + K! B1 e- ?4 I- u7 a' q K% ?- q1 _$ K height: 100vh; $ X! c( X+ k/ A position: absolute;" }! ~9 D( p5 N! K+ L z-index: 100000; : u, p, Q9 N1 @( q$ w0 y% r background-color: rgba(0, 0, 0, .3);, e8 p3 w: m" [9 G9 w7 c O }5 ~1 g1 t) V* @, w, H Z! @% z2 L1 ~8 [* D.dialog { $ j4 D" X' y: f) c1 h& `/ T: K width: 400px; 8 S2 Y, }) [" R9 U* s height: max-content;. M$ P3 L' U6 ] background-color: white; 7 x0 ?' w) @* Q/ w; k! F4 n3 G box-shadow: 0 0 10px #ececec;8 X z& }; W5 E& s+ q) c2 |0 q position: absolute; $ f& E3 ~/ u9 X/ @3 |6 M3 F z-index: 100001;* I# `3 D# S* Q3 K M$ V9 l0 D border-radius: 2px;8 u) M. Z. l) l+ T8 c margin: auto;& {+ K6 u- ^/ w5 a" h2 Z top: 0;: i' r5 g1 ~: Y. T7 j4 {6 H% Y1 i( H bottom: 0;# H: i1 O/ n5 I. R left: 0; 1 w3 X& @& v, A/ @) l right: 0;, d0 @! H$ e p% k } G7 {8 X* }& r! l" G! n.dialog-header {" k. K+ y& z/ F, D5 z display: flex;: K& r& O# F6 y3 A. }; I9 C* a% o align-items: center;* C2 C1 s, f) e* N' F justify-content: space-between; & _$ `( \) t/ n N( e+ \& O border-bottom: 1px solid #ececec; $ U0 r l; V' V- R padding: 10px; 7 A, L1 \- V0 |: y) e}" p" A3 E+ O u- b6 Q $ j' `# V. d/ x+ G2 i: J& j1 k! ? .dialog-header .dialog-title {' L: {3 B8 Y G3 C3 f# G4 Q font-size: 16px; 4 \# ?: b( G. c4 Z/ k} , m& V# e' o% t2 D . \7 B! Q9 r% h. ~$ N6 r( L6 m.dialog-body { W9 g' }( _ v4 w7 S padding: 10px;/ u5 @. z. ~, s' A } ; W) t& A9 }2 o' Y4 _! Z3 V) x8 C) y& c; L+ F/ s .dialog-footer { # W* J- j8 f" R f2 \ display: flex;' r' Y: N2 x* k/ @ justify-content: right; 7 R& y4 R+ f) O: a. P$ Q2 s C padding: 10px;6 i' Q1 ?: q9 z2 }# R; L% m* ~ } 7 O6 ]! F" f/ q; E: l- z( n# v2 ~) @8 o9 K& ]2 A 7 u7 I- I+ x1 j( S# o {#if visible}% i9 y: M: r; x9 T" @ p

* b' P) j( u' u2 O
( D, S6 Q/ g% q& T; L& B
! T# b m( i+ l7 I$ I8 L7 _ c . {0 S: l1 r) c1 {/ ] { title } % f9 j. N/ p" n$ k9 _8 Z- o # \* u9 X6 K: j! R : G. C& ^$ a$ Z/ A# g 5 t/ A3 ^( `, \6 \/ Y Z: Z9 M- L4 R7 R- b : E; S5 v o0 Z% U @
# j! p' D' T7 U' P5 ]5 k1 f+ `0 Y 9 z* \$ @- q$ {* U
' M( u U- R" L! a8 N
+ }7 ]/ e( ^( f0 M 取消 ; z. t/ K& [ g) A" m 确定/ t* S: G9 d: `9 B/ U% r
& m2 i9 q/ ]" S' ^( Q' _
+ r0 _1 F1 ^, b+ J2 z2 F
) \4 b$ t* U* l4 D6 F {/if}

Icon.svelte常用的icon主要通过iconfont来引入! n; B* Z9 F, |' a2 A$ v% F3 Q export let name; ) z) J+ u( q; Q5 z/ _8 t* f2 ]- b8 E) \8 a5 g. X - ?/ ]0 ]' t- ^2 B$ _8 c4 _4 C

Input.svelte7 `: Z( M! i& w5 N; v* p" G4 j export let value;! T$ N& e) w' S$ t3 N; a @ Z import { createEventDispatcher } from svelte;* x+ T& g' I) E const dispatch = createEventDispatcher();! k' V1 [! w6 \* ~/ `9 f3 k9 p function handleChange() { ( D6 @ H) h6 l7 A dispatch(input)9 K/ i* w; e- p' z* X; \1 n9 S5 R }/ I8 S+ G2 ~8 N * y9 }) A5 L: {7 w / U9 p; _2 F& u5 T% d' w* s- @- K9 m) M$ X$ f* s& { .input { 2 k2 I1 S8 w$ F# g border: 1px solid rgb(77, 187, 41, 1);8 l" M1 ]! m! [: f* f- R' a width: 100px;' Y) F; c# T9 M% F; u0 I2 P2 u5 g }2 W+ v3 Y7 |& } ' \* o9 c! k9 H$ E6 P& ~ .input:focus {4 f3 l. t. \$ @0 ~% y( I) _1 E border: 1px solid rgb(77, 187, 41, .5); 5 a( h$ B4 H& L4 Y3 e6 Z# c- o outline: none; 0 L, s6 t. d2 C" h8 J9 g K } 5 K c9 S5 ?8 F1 j! _+ j$ p, W7 J" u* ]7 ^9 v/ r 5 x) k c; x3 Y. ]! k( J7 z

Message.svelte9 L+ l) w3 s! H+ h+ b% U4 n import Icon from ./Icon.svelte;+ c4 E% f; W, N0 g% }) [: U% n export let type = info, show = false; # g: D) Q; X' j6 e6 e7 D$ p( ]; a) \+ l const computedMessageClass = type => {; r- S8 B0 p7 G1 S( n switch (type) { 1 ], B W0 Y5 w+ _% j case success: ; O! O9 }# `: a: r* B, E return message message-success;6 k4 Y. S* b' Q6 } case warning:% ]6 O. F% i# U' c return message message-warning;7 M. M) J' V( C u4 K3 C' L1 G case info: 5 P( I$ p* P3 r7 M return message message-info;+ L0 z. G2 D0 t$ l case error:4 Z: E/ R; K e/ t* a+ J return message message-error; 6 Y/ U/ T2 f+ | default:1 K2 R( L1 B+ ]( |; a7 H3 c0 D return message message-info;; S0 w3 u2 ` S; ` }( A6 U" [* H2 K: [: A5 [ } - ^! u% A+ M) K% `( A2 B) y! D y' P3 n! ]* ~ const computedIconName = type => {6 N7 d9 N6 a2 l& U1 q- ?' v4 | switch (type) {4 I; \/ V4 t7 J" p/ T+ `/ R case success:$ V8 I1 Q2 }" h) {% I$ ] return iconsuccess; 9 r0 u" O; {+ z case warning: 5 c0 A7 i1 r" |0 L return iconwarning;- |0 d% o {) n X! |+ [ case info: ; g0 y( z* a0 V; T1 m \ return iconinfo;8 r/ o. y1 M2 ~ `& {# o case error: 8 T. g) C$ T( i7 Z) } return iconerror;- K. W. [ C. h( {* u7 o default: B0 X r2 E) E3 [. a return iconinfo; 2 X! ~' \1 X9 r% L$ U8 A7 E } 5 i8 b% I5 q% m$ z7 |2 `4 B} ) o9 t* x$ E% l, i" N: x# M" k4 @5 C0 y/ k$ S, B+ X . S1 B& u5 A0 A @9 o8 }+ R+ n * t' S) f* x1 N% L1 C* |: @.message {7 f6 B; P/ U# m6 N position: absolute; 9 Q5 D+ e; z5 ` g z-index: 100000;& N. K7 F: ~& n9 Y6 |& w( C width: 200px; 9 L! S5 u9 B) l+ O! g& d height: max-content;# O, q7 p7 g. h, G$ y1 o) t# x9 r left: 0; 3 q# r2 E; }1 q1 `/ j( F right: 0;2 h) s @( \9 N) y2 Z- y margin: auto;& f1 }. ^# D& ^' p ^- W6 ?* `; ~ padding: 4px 10px;) R' x7 [' Q* [ animation: show 2s ease-in-out forwards;; D0 M+ h% {7 ~" i$ r display: flex;- O) Q# ?$ \0 B1 p# @3 X: ] justify-content: left; 1 F$ _9 U. o1 ~$ z; ^ align-items: center; , v( @5 T0 f; Y+ ]% R8 a* B border-radius: 4px;7 \# M6 D3 s4 h$ m4 S( ~7 P( V& M }; F; l |5 `9 Z' l7 n 6 [0 o8 j. l# K .message-content {/ q# K: i V8 R+ l9 G margin-left: 10px; . o C( E2 A0 p# |; d) ]- L+ V6 y3 _}0 f' R5 z7 p, p3 r0 ?; c6 C 8 m' W& I# j. z" ~' E @keyframes show { % Q5 A6 M2 G v9 b9 w- l from { 7 t/ C! K1 m$ I' b9 W# c, L opacity: 1; ) G$ {( D5 b2 w4 x8 A" @0 Z }- J top: 0; ! X n1 e; J0 S5 {( R5 z* S } # C3 i1 U% w& e: j7 ~# N$ e. @) C. V& N, ]2 ] to { 9 ^; t2 P$ P' O4 h, N' N. B/ H opacity: 0;/ X+ F& F0 ]1 I) w% O top: 100px; - N9 P/ y: z+ p! X } 2 F! i5 i/ | W6 j4 n1 I# \& r} 0 f; \) h! |$ H' A- C3 O8 D4 ~! m) |8 O" [1 ~ .message-success { $ p. c% Z; {$ Z% f7 [! \: J background-color: rgba(77, 187, 41, .2); 3 D1 r2 @/ B& H/ A2 J color: rgba(77, 187, 41, 1);9 _! F w/ Q7 a- a- U; W: a+ d } ; U: W* x: ^- V! M/ ^: }) Z( | / L m" V6 a5 F3 \3 S; O.message-info { 3 V: S3 Z7 Y& J background-color: rgb(144, 147, 153, .2); # ^) n9 ^2 ~ |6 E color: rgb(144, 147, 153, 1); . y# N2 x4 m% k/ I! T# `7 y( ]}+ u8 ~. `5 W/ J ) ]% R; Y! N7 ^! K .message-warning {0 s6 G+ F5 g6 m) o9 b% w background-color: rgb(230, 162, 60, .2); * W* r; _# [6 |$ J0 w color: rgb(230, 162, 60, 1);0 N R/ I: C& `) q' r }9 y( t* Q+ U% \$ g; L, C 1 p0 y9 g: @ J9 o& |7 P1 X.message-error {/ h( {+ l) {- k+ b/ g9 o background-color: rgb(245, 108, 108, .2);: u" {/ B, v4 w1 U1 X* J color: rgb(245, 108, 108, 1); " R. i4 Y$ r! H}; k- `$ J. d3 c# f& _- c9 O l7 I) @& \" }! @1 E x 5 t. l) C4 C- O. `) H{#if show}; G- s& d+ V2 O; q

: L, }- _" l1 s{/if}

Tooltip.svelte 9 ]! N, ^6 R k export let content, tooltip; , j; Y9 i1 S. B ) I0 E* {+ V5 f$ Y; m $ q% H" n; s4 {; H' J8 g8 Z1 j% W0 U8 _- D6 w ) j' Q0 A& |* D4 c; N) L; s .tooltip { s% Y3 u+ V1 k! n3 |8 k position: relative; 4 d5 m; Z: h( E+ M}; V+ v$ G* a3 t4 u * n l5 l, w/ Z2 ]. Q+ D* U .tooltip .tip-container { ; v: d+ ]+ B) l5 O h9 y; L position: absolute;7 b9 i. |3 g$ M- F background: #666; ( m. h. f; E* k9 I* K' S padding: 0 10px; - Y4 ~- Q: v: E3 [' t/ f$ c border-radius: 4px;+ e5 q/ z4 p# F right: -180px; 2 [- K$ G, H f* k- { top: 50%; ' Q7 i; j( P p2 ?# e9 u margin-top: -24px;: I1 A' P9 ?. M1 }. L) X- [. ` }9 n" A4 w8 n+ }9 A5 k/ s0 }% I % d# ^8 R6 K6 W& N6 S.tip-container .tip-triple { 7 D q o/ @! V Y. D width: 0;8 ]0 x( r& o0 |0 [ height: 0;& } V1 w4 O4 H/ N* E7 @ border: 8px solid transparent; ( ] B, Z% n6 u) S0 w1 I: O3 l border-right-color: #666; + h( X0 r" q8 C/ D) } position: absolute;. q- k# F7 u; S. Q. C left: -16px;1 M. }$ s' U0 y: Z8 d top: 16px;0 {" d1 B+ C" B% R+ Y4 Q$ O }% ?5 v' N( ?( w5 c2 w e* O 4 c4 [- s5 ?: s .tip-container .tip-content {% I8 c4 L# ] W, z, Z line-height: 24px;4 M4 s6 y' j% j- r" ^4 f6 U font-size: 12px; $ s3 {2 H( ?/ e7 f, `7 J color: white; ' P7 x6 g" {- z, y; D& s. y} # C6 `1 Z9 e( P. \' b- ?/ Y9 J! P: O2 ~/ C7 b7 O . ^1 f# d+ v6 u) N( v

* v5 c$ @6 g! \/ \ ! B- S7 v7 h& Q! W {#if tooltip} % S" m% {9 D2 q0 |
3 j0 |) Y' M7 Y% {* e . F5 C V3 b0 f2 e3 U0 }( T, ?

{content}

. v# R, n) ]- y: O
- h3 x% E* g" w; D8 D {/if}; U( ?, E8 _% F* ]

Upload.svelte 4 t" |6 |0 o$ C- X. T) m2 }; t export let action, onSuccess, beforeUpload, id;0 w8 c! t9 z' d1 a, J function ajax(options) { $ O8 b! [$ w J' Y$ {" R/ s const xhr = new XMLHttpRequest(); 4 N) d" | L2 }6 L5 ^9 { const action = options.action;; Z. a% B" J" I/ x# F let fd = new FormData(); ; P0 d- m! z/ E+ F$ I- \! ^ 9 s2 ^1 g% v$ B4 w9 X. q fd.append(options.filename, options.file); 6 y& d- ^) [$ d6 A% k; r0 S! @/ C : a, \8 W2 @' [; t4 L7 ? f xhr.onerror = function (err) {. G$ {. ?( y1 H9 \ console.error(err)' d+ g4 c/ v) e$ g0 W } 5 b0 i3 T1 @8 H5 k- A) I - B' i" ?' ?/ y, [$ _ xhr.onload = function() { ! k( N) ^/ P: S0 H$ N- K; L6 h, f const text = xhr.responseText || xhr.response;8 }' l+ n I1 @7 f" v0 ~. P1 W console.log(text, text). M# N$ R+ P7 h8 t: I# c+ B) @/ O text && options.success(JSON.parse(text)) 7 X5 x2 z- Z8 f) v5 I$ t9 Z$ i } 4 Y1 G6 l. b4 a* l' ~/ [- M$ n+ R+ l$ n* s- @3 C9 [% | xhr.open(post, action, true);5 V7 J1 W2 f- l$ [3 ^. W- _4 \' R xhr.send(fd);. R/ z' U/ c# z+ U9 v : v* s7 G+ X6 X% b% s return xhr;0 z, h( V9 I e0 s6 Y1 M. a } 5 |$ R+ j) @8 p+ O function post(rawFile) { 7 D# Y C/ ]3 | const options = { 6 I( b" r6 |- N( J9 d4 H! {7 V4 y id: id, ( e7 l" D" O( U( n: ^, u, H file: rawFile, 8 i) W1 u3 u! x4 T) O2 G% @ filename: img, + I( r6 S) k3 E2 q# u action: action, . I' r J; I- H, j8 d) } success: res => onSuccess(res, rawFile, id)& H! Q4 J3 I* E( b }. f8 d. P# x. B9 \( [ const req = ajax(options); % {4 i3 a/ V2 U1 ~+ T# Y if(req && req.then) { ) Q6 \6 o: T# T req.then(options.onSuccess) ' l$ }. g; a5 F$ F1 ]$ s7 I4 s# M } * |( y5 A0 C: d$ ^ } ( w: k0 t7 \2 {& l async function handleChange(e) { : ?0 r( k: {3 \) k$ X& Z% u( Z! z' f const rawFile = e.target.files[0]; & C$ F+ q3 | C( s/ k if(!beforeUpload) { * o6 A( i x/ S9 V return post(rawFile) + R2 K$ w d! A( Y% L1 p }9 r/ F+ E( b2 V9 e! @+ Z let flag = await beforeUpload(rawFile, id); ( M4 R' V7 ~. C1 |! ?, u. C if(flag) post(rawFile)& c6 v; ?" K- W' ~& `0 z2 V# E } . o) T, J& R+ U) x, X* ?9 q function handleClick() { & b* Q0 \) R- c5 {: B const plus = document.getElementById(id); & \7 S+ X( O. a+ O2 ~% ]8 d plus.value = ;- e# g+ h, `2 ` plus.click()+ B( f& _1 K* O( ?8 W. Q' Y8 n }" R1 I- w7 g5 H( f, P+ } 0 E: B. M: V; f# L+ r B3 E % I( i- F% U# F7 t( t) X; e( u7 r) q" M( E5 f" d) Z# N .upload { 4 z' U* s% p5 l" a, v& Y width: 250px;# j0 w% M" M) s1 ^ height: 250px; 3 c# X: V! a+ k, ~8 P border: 1px dashed #ececec; 5 P/ [( c) r+ \+ ^% Y/ a0 e text-align: center; 4 T# }: Q/ u3 \% O/ E& M+ i& I display: flex; 9 W# t- E4 O5 |& E' ?/ m" O justify-content: center;+ j" s5 q( n& g1 a align-items: center; 0 K" R: P, \# O }) g! n0 N4 u/ d , t9 D; \9 o4 d: G, u( n4 j .upload:hover {) S' x" z( ~# c, }* z# y* B cursor: pointer; T* p, D$ e$ H. l: z% S: g } / k$ D* d n+ y8 J7 g8 ^0 d& ^' N2 X3 J4 Z' I- t .native-input { 5 Y3 X' c0 d) }9 x3 R6 E display: none; ( o0 l) P9 l! ] } & Y: `/ H4 ?3 Z) h+ @ ' ~1 t3 x- {! O h% p, U . j& M% j% p. ?/ `, c) ?9 x

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

6 ]; M) g6 t- N( ?, P. K% n3 A import Icon from ./components/Icon.svelte; . h* t4 G. C4 S& A import Button from ./components/Button.svelte; 1 C+ D: r4 @% H import Upload from ./components/Upload.svelte; . c$ m! T, o* n* j' j( ]2 G import Input from ./components/Input.svelte;& c: d. |4 q% J2 ]7 P5 n' ] import Message from ./components/Message.svelte;5 e: I3 H$ M D. x( b( W4 a" Q import Tooltip from ./components/Tooltip.svelte;' z) p a+ k+ @ import axios from axios; 4 C& V4 l) x6 W. m4 C import { getBase64, getPixel } from ./utils; " T6 V& t* G2 W6 y / v4 B4 N* ]- d: r8 f3 z const bgUrl = ./bg.jpeg,5 ~8 h1 t9 g1 d4 T' Z2 H logoUrl = ./favicon.png, . W" i% r5 V. P, L9 W* } actionUrl = ,! W% S( _. N* C1 X compareUrl = ,$ f& y2 ~& \8 v) y+ L' g downloadUrl = ,/ z( x4 K2 f0 h0 | crxUrl = ;8 ~/ l; S. k0 B% n' X let width = 0, height = 0, flag, compareName, errorMsg, successMsg, show, tooltip; p: s L5 U$ Z1 V/ o let uploaders = [ # O# g, n" N( l. S' z( U { V* S& H+ q* |9 Q/ j id: design, ) p0 Q d. f% {1 C- T5 O title: 设计图,! Y, w; i9 {& L3 r8 d% t0 f filename: , 6 U+ P. \+ s! ^8 |3 b! s url: . ^) T0 [; V$ _ }, # a2 j8 [! a6 I; ?4 g, s4 [6 m7 Q {3 q; x9 x4 V) e3 N8 @ ]( l id: code, 0 K/ W2 X; R$ e0 u s. _* i title: 实现图, 7 y! ]+ |5 d1 a, \( B! ? filename: , 5 v+ n9 x, U" u5 ] url: ! q7 b8 Y. x9 H; C/ s1 R; @ } - O3 a# H9 P" ]2 |% x# F( o6 Y ]; ) z2 k. p- P3 g3 a, F7 s & V. ?) g6 j% ^; w const handleCompare = () => {: e& X% z" w" I I show = false;8 `3 J: S Q: m) @ const len = uploaders.filter(f => !!f.filename).length;. Q# N9 X) B- j0 q3 o1 P if(len == 2) {, |2 ]- H3 e+ w) A) V$ x axios.post(compareUrl, {" L5 u7 u# M ?0 h7 W designName: uploaders[0][filename],. K, [# c) r" K# J+ v3 a5 F codeName: uploaders[1][filename], $ b N; L$ M& G. W( w& O }).then(res => {& R* I+ Q6 s1 ? console.log(compare, res)' n4 [7 z& n9 S9 ^ if(res.data.success) { ! Z- G% N/ `; R% p* a/ u# M compareName = res.data.data.compareName;- H, i! x# x" F: {9 B; ^ return true 5 Q* V6 P8 j) H7 K } else { . M0 M! R: @9 B% T( q flag = error;! t' S1 D0 Y1 S show = true; ! V3 K5 Y2 W3 b errorMsg = res.data.data9 E/ N% v* C z* R } 4 t9 V: V, [2 r: o }).then(c => {+ y8 a. {. T5 `+ h C' s8 y if(c) {2 L5 D+ A: a) n flag = success; 1 h1 Q" Z# a! ~4 Y |* L successMsg = 对比成功;8 d7 O0 `+ @7 B" y3 f7 J7 ? show = true; 2 o1 }2 \) j3 m& [ handleDownload() + `0 u8 p0 ]& f( m$ i handleDelete(): n$ C ?& E( @( Y }$ x: `* C: \) y9 ?8 D8 [ }) - U% V- q" X* d5 {! ^ } else if(len == 1) { 6 \5 w% V+ k( N! h) K window.alert(设计图或开发图缺少,请确认已全部上传后再进行比较!): H2 Y8 p7 k& O, w& p } else {2 F. Z, V: R. o; n2 T' L9 r! t window.alert(必须有图片才能进行比较!) $ d N+ L9 B7 V+ }9 c: c, e- {+ m } 5 X. u/ p4 S1 K };6 r) `6 y/ G$ `8 i4 j5 d; Z + a/ N8 r# [. k9 H const handleBeforeUpload = async function(rawFile, id) {- A6 c! ^% ^7 ?; T: ?6 y6 {+ J0 {: [ const fileBase64 = await getBase64(rawFile);2 C$ x7 h X: M# o0 p2 o6 l) u const res = await getPixel(fileBase64);; M/ s( p2 n7 R$ @5 h' t! @ // console.log(res, res) 2 R+ s9 F& ~% B( Q6 F+ ^6 X4 L if(res.width == width && res.height == height) { $ l$ c1 P+ `9 |# Y- e9 K; G switch (id) {% E% d& M* R( r. w1 _6 f4 [ case design: $ }% q# f& |9 K" L1 D uploaders[0][url] = fileBase64 ) u! {4 ]( @2 C1 b) g6 N break; % Y6 R" A/ @. I! R7 |# m case code:) [8 \! b& H5 ^! \8 \# N2 n2 O uploaders[1][url] = fileBase64 , t* T/ P$ P3 J: ]! I5 E) o break;. }4 }7 S% c" S. _9 Y default: : [6 U1 o$ e( ~) k# X& g% R break;+ o0 w7 C- I) }! O/ i }$ Q/ |8 c9 n: v# o/ P a return true; 3 G8 s$ V. ~$ w2 s } else {( j" y7 x7 N" ^# _ window.alert(上传图片不符合分比率要求);1 C2 J$ M! Q1 K ^; } return false;( ]4 D4 M8 f! U) V) f! l8 p8 @+ _ }5 B/ z7 `( H* o. R }9 s1 e+ D6 l5 M& t1 V' B4 ?8 X# y . D* V2 f/ Y; j7 `1 @8 i const handleSuccess = (response, rawFile, id) => {4 C( L6 S" u9 L7 u o console.log(response, response, rawFile, id); 6 V. r" O8 g( y4 L7 m if(response.success) { & r2 T5 w+ Z `' g1 ~* t% p/ M/ @4 f switch (id) {) e o L! V! p, y7 ~) ?; M: X. M case design: 5 i; S$ {) j* S& h9 C' } uploaders[0][filename] = response.data.filename2 ^- S" p# R5 @ break;- Q. O b! t! t, U ~# l case code: * h/ n& Z. S2 V0 h: | uploaders[1][filename] = response.data.filename4 p" F7 N+ C' E. |0 g7 } break;* H" _7 X! H u9 i/ k6 A& |9 _ default: 4 F; k+ y3 U9 R+ X, B; q break; ! w( O: i# [5 V5 f; r& c0 G }( f' H: _- X3 ^6 O2 s } 2 }+ M8 G8 I% E4 ?: M } + J! T, Y2 X0 B$ p& x5 j0 u - P0 i# p6 V% A/ Z function handleDownload() {- Q: F0 N; U5 T# n: X: } axios({ s' {5 i5 l6 U' m L* G0 z method: POST,5 F0 L& A) F% M! U/ [0 d url: downloadUrl, 0 J; |1 B. f$ w r& | responseType: blob,# m' i/ g r7 T! p% Y data: { , Y. b+ D [4 N! A2 `. F compareName: compareName ! ]; o: {# J4 ^: Z' t } v- m+ }' G# _, {+ U) r }).then(res => { 4 {6 ^& |9 f/ o' b console.log(download, res) 8 X5 H" J, R& x. N# P if(res.status == 200) {9 r* R3 {# u) P var blob = new Blob([res.data]); ( m2 A1 T6 q7 Y( V3 S b; ]; Z1 d // 创建一个URL对象" w3 z) t3 I, C" Q6 L var url = window.URL.createObjectURL(blob);5 g) Y! Q a5 o6 p9 S$ [: N console.log(url, url) - i/ `' Q* `$ L; J5 m8 {$ S: u4 M // 创建一个a标签. S. b7 ?" i {& R var a = document.createElement("a"); 4 g" O9 _2 d: y5 _6 r a.href = url; $ V: R4 d3 {& J' T# Q# Z/ @ a.download = compareName;// 这里指定下载文件的文件名 , F- i, e" ~: x- w4 V( p a.click();8 H% I4 T2 C2 _: m/ Z- f# |5 X // 释放之前创建的URL对象) ]( X8 P5 j _6 h% N window.URL.revokeObjectURL(url); 7 i# T: `+ E2 q& g& h4 E4 ]- q" Q } ' o2 i3 H* O2 l E, h }) + {" m6 u% G) Y5 ]8 I }" p1 d! c8 D7 w( ?9 C# h. c; v 1 ^5 [: v3 n" C function handleDelete() {* h% x. t, F* }+ H: N' ^- E uploaders = [1 n* i: k" r; B {5 m1 o) @( F5 o! b4 B- ] id: design,. M" {' A0 W; c* V$ s title: 设计图, 9 T/ k; P E* X, e7 J" F! K filename: , % d G" O- M& P url: % d" Y, C8 T1 y! U; g1 s2 Y* _ }, + ?, T* Q, g1 r1 k1 S5 f { 3 c9 }) F' l6 h9 W id: code,# f# a, K, r4 ] E' J title: 实现图, ' Z/ V" [4 A% F, ~0 n9 W& h! ~7 r4 P filename: , W2 r! q; c. [" r4 E url: 2 B% A9 ~6 T/ q& S' c } : N; x2 H: O! x4 A3 R1 l7 V ]; + [4 P% D2 ?4 T; f } . v& U0 r# c7 T- A& o- h' F3 Z! A5 v3 e$ \0 x. v6 G8 @ + r4 h, w, `8 r. D; F; k, k . k k- X3 ]- G, t .pixel-piper { 3 E- P% b$ G9 q1 e- D; d. p1 X3 B. t width: 100%;7 ^1 u/ d' |7 d0 h6 t height: 100%;- j& r1 }* n7 m& n display: flex; C+ T# |7 `% [4 I; K justify-content: center;, J% Z# _7 N1 F align-items: center;. g* F, _8 J+ G4 K( O! G: W }( u8 B, @! r! K) w: g! k' g 4 t+ H0 _6 n) P" t* L* D. h .main {* T) @" O( j5 W5 ]1 G, w V z width: 600px;; u) N: J M& B5 S7 R margin: 0 auto;1 {/ c2 _6 ]( P- ?* \5 \, m$ } padding: 20px;) l9 q- ^* v8 N: ], \ border: 1px solid #eee;, d5 b' h! Y" M! v background-color: #fff;" l+ ?+ Z1 y& ?) X8 C border-radius: 4px; & c8 i6 q$ R2 k7 Q" p: B' o! g N box-shadow: 0 0 10px #e0e0e0; 2 g- E' Z5 k1 a# L4 q2 F1 ] } 8 @2 Q8 Q2 Z ~( n. @; r2 d3 r! b: [- Y .main .logo-container {: F; D/ K' p/ d o- o display: flex; $ z& ~0 F! `1 n; R; A7 m& h. X. M( O justify-content: center; + I6 g# p4 Q! z. H) @- m align-items: center;% S5 q- H. I# t } , g' a+ q3 E* d' y- P+ X0 @! a! ^1 ]- [ H- X$ S/ m .logo-container .logo:hover {6 H0 o( q' ^( ]/ I9 u6 p opacity: 90%; 7 w5 a- F) w; y$ t' z cursor: pointer;" @. y0 `% ~; L& V. L# \3 D% B3 _ } 2 v8 A/ t+ v0 n; ^ H7 a' w # ^; S; }: m& S3 ~+ f4 G! ` .main .select-container {- y9 o/ B: Z5 H1 |6 x6 W display: flex; . i4 V& B: n+ l: ]+ Q* }3 l align-items: center; ( F' ^+ Y* g" Z. ` align-content: center;7 ?% S; s3 T* E+ I/ E: Q justify-content: center; 9 n3 A! \. F1 i( v8 S2 X justify-items: center; 5 n% d6 G, b0 G8 }, R3 [ line-height: 40px;7 U4 T% f) w# D8 i) x* F' H }) P: \) L8 C: \1 Z 4 E4 x9 u, D% H .main .upload-container {8 @5 I$ l3 @5 m* H display: flex; % U- B, C8 C1 O5 h5 W8 s* z: @ padding: 0 0 10px 0;6 }) ^# k/ r7 p" P justify-content: space-between; 3 F" v( j" H; x text-align: center;6 F; _/ N2 l$ Q } / W/ w3 X( [7 i1 q! h _- t0 ^( y5 H; j: D9 V) Q$ q! Z .main .button-container {0 ^' s: Q( w9 y" z$ n$ ^0 s display: flex;. [2 u& v" v6 W* _% d: ] justify-content: center;+ z* m2 c$ L9 N: C* @: S0 O9 G align-items: center;0 B& H2 q3 t4 V2 d# f* |9 o& o }0 }9 n/ Q# u& ~" D$ F $ V1 B) ]' Y3 d .main .info-container {% k( |1 K# u/ b+ T# q3 W text-align: center; , n1 U$ ~5 D. ^( ]& e, Q color: red;; Q8 x* y( K7 R+ _( g1 u5 W' H& H font-size: 12px;3 d3 u/ z5 t: e8 S" L) U8 f+ Q margin: 10px 0;2 `! n7 j+ f: `5 F. X } 6 k: X5 W6 W Z0 t0 w( L0 l9 c; B' Z0 z1 n9 C6 e% L+ b 0 c F6 C: ^) Z1 e; w

4 G# D5 O8 c. a5 S . [. R' B- }* Y$ f# x3 @
( ?1 |5 H5 q% C8 q) `0 P+ W; _" }4 t 0 f8 H1 t1 ], P7 r" C4 ? 1 y& S0 H( X" H1 e( \. `3 D tooltip=true} ) G( v$ W- X }: G* ? on:mouseleave={() => tooltip=false}0 `' f4 D( n! }; V > 8 L! l) G3 t: g 2 P k1 K% W5 t% E 7 q7 s. L% v5 v
" ~9 y4 p0 T+ b+ c
( r' V, S' K/ K# N

x

( P% X7 A6 `' a7 s( v! r) w0 `, D
; m! J: t7 H; ^! n4 ^
6 P4 d( [( V3 }( R- T, q, ~ {#each uploaders as uploader}6 n V5 m1 _7 b2 w
+ K" X' O3 m% [. v8 o X; V" G 2 U4 ^0 X3 q5 \4 o' ] {#if !uploader.url} 1 H6 x; v, _1 R* V/ e 0 A- a6 Q# d6 p! H) s2 V3 ] {:else} & M! C/ v( O* V2 _ " ~! O! n+ h8 Z( R {/if} / V. j4 C9 O, Q6 [2 ~2 J5 \ / I4 b5 }# C5 B3 [* V# I {uploader.title}- s& T/ N2 [: S4 G8 F
9 G+ \2 l/ f5 K( [( l- J5 u k! R5 u {/each}- _' l* ]: @ Y) T4 b0 I0 O5 p3 v& W
8 e8 Q7 d; |6 x. A$ A# \* ]
6 W$ p1 R) _( m% u; E {#if uploaders.filter(f => !!f.filename).length == 2}- U7 r6 z& b/ J$ i 注:请在两分钟内进行图片对比!! 7 r+ i" n6 E3 i- ?4 n) _* m {/if} 7 }: O4 D" D: g; @) v: V0 o0 h! b
8 I; `6 X+ m/ x
4 A) p6 g1 {+ w# v5 u0 Y, C g 对比 ( ^* {8 A1 p; I1 \% C {#if uploaders.filter(f => !!f.filename).length == 2}% {3 a0 G' Y+ r( c
+ M: y6 ]: }0 b+ Y 清除图片' k* m; N: P1 {/ r$ r
9 S4 o4 F4 u2 I! H7 z5 Y( I) [ {/if}3 Z7 j; u8 Z C' g" F2 P3 b9 O% R
. O& @: e8 I) f0 H8 i/ M+ P / g+ L; {; k( g0 ~/ s2 `+ ^ {#if flag == success}. }' a" j; E# E; X {successMsg} 7 {, h3 }: e. {) Y7 v' C5 I {:else if flag == error} 5 A) Y# @( ] h* y/ i0 { {errorMsg}& i8 p+ A' p1 m' S0 q9 Z {/if} / k4 l6 }0 k# T; N' q& N

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

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

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

回复

使用道具 举报

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

    本版积分规则

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

    GMT+8, 2026-7-7 14:13 , Processed in 0.037192 second(s), 25 queries , Gzip On.

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

    Powered by Discuz! X3.5

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