1010 @click =" saveLinkFun" v-if =" nowType === 1" >保存</el-button >
1111 <el-button icon =" el-icon-edit" size =" mini"
1212 v-if =" linkList.length > 0 && nowType === 0"
13- @click =" editLinkFun" >编辑</el-button >
13+ @click =" editLinkFun" >添加/ 编辑</el-button >
1414 </div >
1515 <div style =" margin-left : 20px ;" v-if =" linkList.length > 0 && nowType === 0" >
16+ <el-button icon =" el-icon-s-operation" size =" mini"
17+ @click =" importJsonFun" >导入链接</el-button >
1618 <el-button icon =" el-icon-s-operation" size =" mini"
1719 @click =" exportJsonFun" >导出链接</el-button >
1820 </div >
21+ </div >
22+ <div class =" list-link" v-if =" mode == 0" >
23+ <div class =" list-link-item" v-for =" (value, index) in linkList" :key =" index" >
24+ <a :href =" value.url" target =" __blank" >
25+ {{value.title}}
26+ <i class =" el-icon-s-promotion" ></i >
27+ </a >
28+ </div >
1929 </div >
2030 <el-table
31+ v-if =" mode == 1"
2132 :data =" linkList"
2233 style =" width : 100% " >
2334 <el-table-column
5263 </template >
5364 </el-table-column >
5465 </el-table >
55- <el-input
56- type =" textarea"
57- :rows =" 2"
58- v-if =" showExport"
59- v-model =" exportJson" >
60- </el-input >
66+ <div v-if =" showExport || showImport" class =" import-area" >
67+ <el-input
68+ type =" textarea"
69+ autosize =" true"
70+ v-model =" exportJson" >
71+ </el-input >
72+ <el-button size =" mini" v-if =" showImport" @click =" doImport" >点击导入</el-button >
73+ </div >
6174 </div >
6275</template >
6376<script >
@@ -66,9 +79,11 @@ export default {
6679 return {
6780 linkList: [{ url: ' https://regex101.com/' , title: ' 正则' }, { url: ' http://github.com/zhimin-dev/chrome-extension' , title: ' 本插件Github' }],
6881 showExport: false ,
82+ showImport: false ,
6983 exportJson: ' ' ,
7084 nowType: 0 ,
7185 showDelete: false ,
86+ mode: 0 , // 0 链接 1 显示表格
7287 };
7388 },
7489 created () {
@@ -84,8 +99,33 @@ export default {
8499 methods: {
85100 saveLink () {
86101 localStorage .setItem (' linkUrl' , JSON .stringify (this .linkList ));
102+ this .mode = 0 ;
103+ },
104+ doImport () {
105+ const row = this .exportJson ;
106+ try {
107+ const list = JSON .parse (row);
108+ for (let i = 0 ; i < list .length ; i += 1 ) {
109+ if (list[i].url !== undefined && list[i].title !== undefined ) {
110+ this .linkList .push (this .setObj (list[i].title , list[i].url , true ));
111+ }
112+ }
113+ this .saveLink ();
114+ this .exportJson = ' ' ;
115+ } catch (e) {
116+ console .log (e);
117+ }
118+ },
119+ importJsonFun () {
120+ this .showExport = false ;
121+ if (! this .showImport ) {
122+ this .showImport = true ;
123+ } else {
124+ this .showImport = false ;
125+ }
87126 },
88127 exportJsonFun () {
128+ this .showImport = false ;
89129 if (! this .showExport ) {
90130 this .showExport = true ;
91131 this .exportJson = JSON .stringify (this .linkList );
@@ -94,15 +134,19 @@ export default {
94134 }
95135 },
96136 getEmptyObj () {
137+ return this .setObj (' ' , ' ' , true );
138+ },
139+ setObj (title , url , canEdit ) {
97140 return {
98- title: ' ' ,
99- url: ' ' ,
100- canEdit: true ,
141+ title,
142+ url,
143+ canEdit,
101144 };
102145 },
103146 addLinkFun () {
104147 this .nowType = 1 ;
105148 this .linkList .push (this .getEmptyObj ());
149+ this .mode = 1 ;
106150 },
107151 saveLinkFun () {
108152 this .showDelete = false ;
@@ -123,9 +167,11 @@ export default {
123167 for (let i = 0 ; i < this .linkList .length ; i += 1 ) {
124168 this .linkList [i].canEdit = true ;
125169 }
170+ this .mode = 1 ;
126171 },
127172 deleteRowFun (index ) {
128173 this .linkList .splice (index, 1 );
174+ this .mode = 1 ;
129175 },
130176 cancelLinkFun () {
131177 if (this .nowType === 1 && ! this .showDelete ) {
@@ -136,7 +182,21 @@ export default {
136182 this .linkList [i].canEdit = false ;
137183 }
138184 this .showDelete = false ;
185+ this .mode = 0 ;
139186 },
140187 },
141188};
142189 </script >
190+ <style lang="sass" scope>
191+ .list-link
192+ display : flex
193+ flex-wrap : wrap ;
194+ .list-link-item
195+ margin-right : 15px
196+ padding : 10px
197+ a
198+ color : #000
199+ text-decoration : none
200+ .import-area
201+ display : flex ;
202+ </style >
0 commit comments