6
6
<span class =" tip" >{{tip}}</span >
7
7
</div >
8
8
</div >
9
- <instance v-else @init = " init " ></instance >
9
+ <instance v-else ></instance >
10
10
</div >
11
11
</template >
12
12
@@ -15,6 +15,7 @@ import { mapState, mapMutations, mapGetters } from 'vuex'
15
15
import Instance from ' ./components/instance.vue'
16
16
import InstanceLoader from ' ./components/loader.vue'
17
17
import IframeHandler from ' @utils/editor/handleInstanceView'
18
+ import localStore from ' @utils/local-storage'
18
19
/* css */
19
20
import ' @assets/css/codemirror.css'
20
21
import ' @assets/css/codemirror-dialog.css'
@@ -33,12 +34,10 @@ export default {
33
34
rendered: false ,
34
35
}
35
36
},
36
- created () {
37
+ mounted () {
38
+ IframeHandler .clearIframe ()
37
39
this .resetInstanceState ()
38
- },
39
- async mounted () {
40
- await this .init ()
41
- this .rendered = true
40
+ this .init ()
42
41
},
43
42
watch: {
44
43
clientWidth (newW , oldW ) {
@@ -85,6 +84,7 @@ export default {
85
84
this .setIframeH (iframeH + avgH)
86
85
this .setConsoleH (consoleH + avgH)
87
86
},
87
+ $route () {},
88
88
},
89
89
computed: {
90
90
... mapState ([
@@ -96,7 +96,7 @@ export default {
96
96
' loginState' ,
97
97
' loginInfo' ,
98
98
]),
99
- ... mapGetters ([' isSelfProfile' ])
99
+ ... mapGetters ([' isSelfProfile' , ' isSelfInstance ' ]),
100
100
},
101
101
methods: {
102
102
... mapMutations ([
@@ -109,17 +109,18 @@ export default {
109
109
' setCurTab' ,
110
110
' setInstancesCode' ,
111
111
' setInstanceSetting' ,
112
+ ' setAllInstanceSetting' ,
112
113
' setAllInstanceExtLinks' ,
113
114
' resetInstanceState' ,
114
115
]),
115
116
async init () {
117
+ this .rendered = false
116
118
this .loaded = false
117
119
await this .initInstanceInfo ()
118
- if (! this .rendered ) {
119
- await this .calcSize ()
120
- }
120
+ await this .calcSize ()
121
121
// 完成后隐藏全页面的加载动画
122
122
this .loaded = true
123
+ this .rendered = true
123
124
},
124
125
async calcSize () {
125
126
this .tip = ' 实例页面加载中'
@@ -149,7 +150,19 @@ export default {
149
150
},
150
151
async initInstanceInfo () {
151
152
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
+ }
153
166
const { username , instanceID: exampleId } = route .params
154
167
this .tip = ' 正在请求实例信息'
155
168
try {
@@ -163,23 +176,39 @@ export default {
163
176
htmlStyle ,
164
177
cssStyle ,
165
178
jsStyle ,
179
+ name: nickname ,
180
+ myFavorites ,
166
181
} = res .data
167
182
const { instanceCode , instanceExtLinks , headTags } =
168
183
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
+ })
170
193
this .setAllPrep ([htmlStyle, cssStyle, jsStyle])
171
194
this .setCurTab (htmlStyle)
172
195
this .setInstancesCode (instanceCode)
173
196
this .setInstanceSetting ({ name: ' headTags' , value: headTags })
174
197
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
+ }
175
203
this .$message .success (' 获取实例信息成功!' )
176
204
} else {
177
205
this .$message .error (' 获取实例信息失败!' )
178
- this .$router .replace ({ name : ' 404 ' } )
206
+ this .$router .go ( - 1 )
179
207
}
180
208
} catch (err) {
181
209
console .log (err)
182
- this .$router .replace ({ name: ' 404' })
210
+ this .$message .error (' 实例不存在!' )
211
+ this .$router .replace (' /404' )
183
212
}
184
213
},
185
214
},
@@ -199,12 +228,14 @@ export default {
199
228
okText: ' 退出' ,
200
229
}).then ((isLogout ) => {
201
230
if (isLogout) {
202
- new IframeHandler ().clearIframe ()
231
+ IframeHandler .clearIframe ()
232
+ this .resetInstanceState ()
203
233
}
204
234
next (isLogout)
205
235
})
206
236
} else {
207
- next (true )
237
+ IframeHandler .clearIframe ()
238
+ next ()
208
239
}
209
240
},
210
241
}
0 commit comments