Skip to content

Commit 1f6e0d8

Browse files
committed
添加私有实例特性
1 parent dbf9705 commit 1f6e0d8

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

src/components/dialog/instanceConfig.vue

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
</v-chip>
2323
</template>
2424
</v-combobox>
25+
<span class="form-item-title">公共性</span>
26+
<span class="text-describe">将实例设置为私有,其他人将不会访问到你的实例。但每位用户最多只能有5个私有实例</span>
27+
<v-radio-group v-model="form.ispublic" row mandatory>
28+
<v-radio label="公共" :value="true"></v-radio>
29+
<v-radio label="私有" :value="false"></v-radio>
30+
</v-radio-group>
2531
</v-form>
2632
</v-card-text>
2733
<v-card-actions style="padding-bottom:20px">
@@ -41,6 +47,7 @@ export default {
4147
form: {
4248
title: '',
4349
tags: [],
50+
ispublic: true,
4451
},
4552
rules: {
4653
title: [(v) => !!v || '请填写实例标题!'],
@@ -60,10 +67,11 @@ export default {
6067
}
6168
},
6269
created() {
63-
const { title, tags } = this.curInstanceDetail
70+
const { title, tags, ispublic } = this.curInstanceDetail
6471
this.form = {
6572
title,
6673
tags: tags ? tags.split(',') : [],
74+
ispublic,
6775
}
6876
},
6977
computed: {
@@ -83,19 +91,31 @@ export default {
8391
if (!this.validate()) return void 0
8492
this.loading = true
8593
try {
86-
const { title, tags } = this.form
87-
const res = await this.$http.configWork({
88-
exampleId: this.curInstanceDetail.id,
94+
const { title, tags, ispublic } = this.form
95+
const { id, ispublic: oldIspublic } = this.curInstanceDetail
96+
const reqObj = {
97+
exampleId: id,
8998
label: tags.toString(),
9099
exampleName: title,
91-
})
100+
}
101+
if (ispublic !== oldIspublic) {
102+
reqObj.ispublic = ispublic
103+
}
104+
const res = await this.$http.configWork(reqObj)
92105
if (res.state) {
93106
this.setVisibleDialogName('')
94107
this.setCurInstanceDetail({ title, tags: tags.toString() })
95-
this.setVisibleDialogName('')
96108
this.$message.success('实例设置修改成功!')
97109
} else {
98-
this.$message.success('实例设置修改失败!')
110+
switch (res.msg) {
111+
case 1: {
112+
this.$message.error('私有实例已达上限!')
113+
break
114+
}
115+
default: {
116+
this.$message.error('实例设置修改失败!')
117+
}
118+
}
99119
}
100120
} catch (err) {
101121
console.log(err)

src/components/selfInstanceCard.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<div class="img-screen pointer d-flex flex-ai flex-jcc" @click="viewInstance">
55
<v-icon>mdi-eye</v-icon>
66
</div>
7+
<div class="private" v-if="!info.ispublic">
8+
<v-icon>mdi-lock</v-icon>
9+
</div>
710
</v-img>
811
<v-card-actions>
912
<div class="instance-info d-flex flex-clo pointer">
@@ -180,6 +183,12 @@ export default {
180183
opacity: 1;
181184
}
182185
}
186+
.private {
187+
position: absolute;
188+
right: 10px;
189+
top: 10px;
190+
text-shadow: 0 2px 4px $deep-5;
191+
}
183192
}
184193
.instance-info {
185194
margin-left: 10px;

src/views/instance/index.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export default {
178178
jsStyle,
179179
name: nickname,
180180
myFavorites,
181+
ispublic,
181182
} = res.data
182183
const { instanceCode, instanceExtLinks, headTags } =
183184
JSON.parse(codeContent)
@@ -187,6 +188,7 @@ export default {
187188
id,
188189
title,
189190
tags,
191+
ispublic,
190192
liked: myFavorites,
191193
saved: true,
192194
})

0 commit comments

Comments
 (0)