Skip to content

Commit 2481960

Browse files
authored
Merge pull request #92 from Raxcl/feature-cos-final1
[add]: 新增腾讯云图床
2 parents c6a3ac2 + 03cdcd4 commit 2481960

File tree

5 files changed

+460
-0
lines changed

5 files changed

+460
-0
lines changed

blog-cms/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"axios": "0.24.0",
1313
"core-js": "3.6.5",
14+
"cos-js-sdk-v5": "^1.4.10",
1415
"echarts": "4.9.0",
1516
"element-ui": "2.13.2",
1617
"lodash": "4.17.19",

blog-cms/src/api/cos.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import COS from 'cos-js-sdk-v5';
2+
3+
// todo 该cos只初始化一次,待优化
4+
// 未配置的情况下,点击腾讯云界面会报错, 请在配置后刷新页面
5+
const txyunConfig = JSON.parse(localStorage.getItem('txyunConfig'))
6+
console.log("cos配置:",txyunConfig)
7+
const cos = new COS({
8+
SecretId: txyunConfig.secretId,
9+
SecretKey: txyunConfig.secretKey,
10+
});
11+
12+
export default cos;

blog-cms/src/router/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ const routes = [
148148
component: () => import('@/views/pictureHosting/UpyunManage'),
149149
meta: {title: '又拍云', icon: 'el-icon-folder-opened'}
150150
},
151+
{
152+
path: 'txyun',
153+
name: 'TxyunManage',
154+
component: () => import('@/views/pictureHosting/TxyunManage'),
155+
meta: {title: '腾讯云', icon: 'el-icon-folder-opened'}
156+
},
151157
]
152158
},
153159
{

blog-cms/src/views/pictureHosting/Setting.vue

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@
4848
<el-button type="info" size="medium" icon="el-icon-close" @click="saveUpyun(false)">清除配置</el-button>
4949
</el-form>
5050
</el-card>
51+
52+
<el-card>
53+
<div slot="header">
54+
<span>腾讯云存储配置</span>
55+
</div>
56+
<el-form :model="txyunConfig" label-width="100px">
57+
<el-form-item label="secret-id">
58+
<el-input v-model="txyunConfig.secretId"></el-input>
59+
</el-form-item>
60+
<el-form-item label="secret-key">
61+
<el-input v-model="txyunConfig.secretKey"></el-input>
62+
</el-form-item>
63+
<el-form-item label="存储空间名">
64+
<el-input v-model="txyunConfig.bucketName"></el-input>
65+
</el-form-item>
66+
<el-form-item label="地域">
67+
<el-input v-model="txyunConfig.region"></el-input>
68+
</el-form-item>
69+
<el-form-item label="CDN访问域名">
70+
<el-input v-model="txyunConfig.domain"></el-input>
71+
</el-form-item>
72+
<el-button type="primary" size="medium" icon="el-icon-check" :disabled="!isTxyunSave" @click="saveTxyun(true)">保存配置</el-button>
73+
<el-button type="info" size="medium" icon="el-icon-close" @click="saveTxyun(false)">清除配置</el-button>
74+
</el-form>
75+
</el-card>
5176
</div>
5277
</template>
5378

@@ -70,11 +95,21 @@ export default {
7095
bucketName: '',
7196
domain: ''
7297
},
98+
txyunConfig: {
99+
secretId: '',
100+
secretKey: '',
101+
bucketName: '',
102+
region: '',
103+
domain: ''
104+
},
73105
}
74106
},
75107
computed: {
76108
isUpyunSave() {
77109
return this.upyunConfig.username && this.upyunConfig.password && this.upyunConfig.bucketName && this.upyunConfig.domain
110+
},
111+
isTxyunSave() {
112+
return this.txyunConfig.secretId && this.txyunConfig.secretKey && this.txyunConfig.bucketName && this.txyunConfig.region && this.txyunConfig.domain
78113
}
79114
},
80115
created() {
@@ -92,6 +127,11 @@ export default {
92127
this.upyunConfig = JSON.parse(upyunConfig)
93128
}
94129
130+
const txyunConfig = localStorage.getItem('txyunConfig')
131+
if (txyunConfig) {
132+
this.txyunConfig = JSON.parse(txyunConfig)
133+
}
134+
95135
const userJson = window.localStorage.getItem('user') || '{}'
96136
const user = JSON.parse(userJson)
97137
if (userJson !== '{}' && user.role !== 'ROLE_admin') {
@@ -131,6 +171,16 @@ export default {
131171
this.msgSuccess('清除成功')
132172
}
133173
}
174+
,
175+
saveTxyun(save) {
176+
if (save) {
177+
localStorage.setItem('txyunConfig', JSON.stringify(this.txyunConfig))
178+
this.msgSuccess('保存成功')
179+
} else {
180+
localStorage.removeItem('txyunConfig')
181+
this.msgSuccess('清除成功')
182+
}
183+
}
134184
}
135185
,
136186
}

0 commit comments

Comments
 (0)