66 <span class =" tip" >{{tip}}</span >
77 </div >
88 </div >
9- <instance v-else @init = " init " ></instance >
9+ <instance v-else ></instance >
1010 </div >
1111</template >
1212
@@ -15,6 +15,7 @@ import { mapState, mapMutations, mapGetters } from 'vuex'
1515import Instance from ' ./components/instance.vue'
1616import InstanceLoader from ' ./components/loader.vue'
1717import IframeHandler from ' @utils/editor/handleInstanceView'
18+ import localStore from ' @utils/local-storage'
1819/* css */
1920import ' @assets/css/codemirror.css'
2021import ' @assets/css/codemirror-dialog.css'
@@ -33,12 +34,10 @@ export default {
3334 rendered: false ,
3435 }
3536 },
36- created () {
37+ mounted () {
38+ IframeHandler .clearIframe ()
3739 this .resetInstanceState ()
38- },
39- async mounted () {
40- await this .init ()
41- this .rendered = true
40+ this .init ()
4241 },
4342 watch: {
4443 clientWidth (newW , oldW ) {
@@ -85,6 +84,7 @@ export default {
8584 this .setIframeH (iframeH + avgH)
8685 this .setConsoleH (consoleH + avgH)
8786 },
87+ $route () {},
8888 },
8989 computed: {
9090 ... mapState ([
@@ -96,7 +96,7 @@ export default {
9696 ' loginState' ,
9797 ' loginInfo' ,
9898 ]),
99- ... mapGetters ([' isSelfProfile' ])
99+ ... mapGetters ([' isSelfProfile' , ' isSelfInstance ' ]),
100100 },
101101 methods: {
102102 ... mapMutations ([
@@ -109,17 +109,18 @@ export default {
109109 ' setCurTab' ,
110110 ' setInstancesCode' ,
111111 ' setInstanceSetting' ,
112+ ' setAllInstanceSetting' ,
112113 ' setAllInstanceExtLinks' ,
113114 ' resetInstanceState' ,
114115 ]),
115116 async init () {
117+ this .rendered = false
116118 this .loaded = false
117119 await this .initInstanceInfo ()
118- if (! this .rendered ) {
119- await this .calcSize ()
120- }
120+ await this .calcSize ()
121121 // 完成后隐藏全页面的加载动画
122122 this .loaded = true
123+ this .rendered = true
123124 },
124125 async calcSize () {
125126 this .tip = ' 实例页面加载中'
@@ -149,7 +150,19 @@ export default {
149150 },
150151 async initInstanceInfo () {
151152 const route = this .$route
152- if (route .name !== ' Work' ) return void 0
153+ const settings = JSON .parse (localStore .get (' JSE_PERSONAL_SETTINGS' ))
154+ if (route .name !== ' Work' ) {
155+ if (this .loginState && settings) {
156+ const { prep , code , indent , font , headTags } = settings
157+ this .setAllPrep (prep)
158+ this .setCurTab (prep[0 ])
159+ this .setInstancesCode (code)
160+ this .setInstanceSetting ({ name: ' indent' , value: indent })
161+ this .setInstanceSetting ({ name: ' font' , value: font })
162+ this .setInstanceSetting ({ name: ' headTags' , value: headTags })
163+ }
164+ return void 0
165+ }
153166 const { username , instanceID: exampleId } = route .params
154167 this .tip = ' 正在请求实例信息'
155168 try {
@@ -163,23 +176,39 @@ export default {
163176 htmlStyle ,
164177 cssStyle ,
165178 jsStyle ,
179+ name: nickname ,
180+ myFavorites ,
166181 } = res .data
167182 const { instanceCode , instanceExtLinks , headTags } =
168183 JSON .parse (codeContent)
169- this .setCurInstanceDetail ({ username, id, title, tags, saved: true })
184+ this .setCurInstanceDetail ({
185+ username,
186+ nickname,
187+ id,
188+ title,
189+ tags,
190+ liked: myFavorites,
191+ saved: true ,
192+ })
170193 this .setAllPrep ([htmlStyle, cssStyle, jsStyle])
171194 this .setCurTab (htmlStyle)
172195 this .setInstancesCode (instanceCode)
173196 this .setInstanceSetting ({ name: ' headTags' , value: headTags })
174197 this .setAllInstanceExtLinks (instanceExtLinks)
198+ if (this .isSelfInstance && settings) {
199+ const { indent , font } = settings
200+ this .setInstanceSetting ({ name: ' indent' , value: indent })
201+ this .setInstanceSetting ({ name: ' font' , value: font })
202+ }
175203 this .$message .success (' 获取实例信息成功!' )
176204 } else {
177205 this .$message .error (' 获取实例信息失败!' )
178- this .$router .replace ({ name : ' 404 ' } )
206+ this .$router .go ( - 1 )
179207 }
180208 } catch (err) {
181209 console .log (err)
182- this .$router .replace ({ name: ' 404' })
210+ this .$message .error (' 实例不存在!' )
211+ this .$router .replace (' /404' )
183212 }
184213 },
185214 },
@@ -199,12 +228,14 @@ export default {
199228 okText: ' 退出' ,
200229 }).then ((isLogout ) => {
201230 if (isLogout) {
202- new IframeHandler ().clearIframe ()
231+ IframeHandler .clearIframe ()
232+ this .resetInstanceState ()
203233 }
204234 next (isLogout)
205235 })
206236 } else {
207- next (true )
237+ IframeHandler .clearIframe ()
238+ next ()
208239 }
209240 },
210241}
0 commit comments