去掉设置页tab,并将社区源选择的select修改为只有主源和备源的单选

This commit is contained in:
sunxiyuan 2020-04-10 15:07:28 +08:00
parent d25c4d3129
commit 24e6a23fd1
2 changed files with 73 additions and 98 deletions

View file

@ -78,8 +78,17 @@ class WP_CHINA_YES {
} }
$options = get_option('wp_china_yes_options'); $options = get_option('wp_china_yes_options');
$api_server = $options["custom_api_server"] ?: $options["api_server"];
$download_server = $options["custom_download_server"] ?: $options["download_server"]; if ($options["community"] == 1) {
$api_server = 'api.w.org.ixmu.net';
$download_server = 'd.w.org.ixmu.net';
} else {
$api_server = 'api.w.org.ibadboy.net';
$download_server = 'd.w.org.ibadboy.net';
}
$api_server = $options["custom_api_server"] ?: $api_server;
$download_server = $options["custom_download_server"] ?: $download_server;
$url = str_replace('api.wordpress.org', $api_server, $url); $url = str_replace('api.wordpress.org', $api_server, $url);
$url = str_replace('downloads.wordpress.org', $download_server, $url); $url = str_replace('downloads.wordpress.org', $download_server, $url);
@ -146,15 +155,13 @@ EOT;
} }
public static function set_config() { public static function set_config() {
if (( ! array_key_exists('api_server', $_POST) && ! array_key_exists('download_server', $_POST)) || if ( ! array_key_exists('community', $_POST) ||
( ! array_key_exists('community', $_POST) && ! array_key_exists('custom_api_server', $_POST) && ! array_key_exists('custom_download_server', $_POST))) { ( ! array_key_exists('custom_api_server', $_POST) && ! array_key_exists('custom_download_server', $_POST))) {
self::error('参数错误', - 1); self::error('参数错误', - 1);
} }
self::set_wp_option( self::set_wp_option(
sanitize_text_field(trim($_POST['community'])), sanitize_text_field(trim($_POST['community'])),
sanitize_text_field(trim($_POST['api_server'])),
sanitize_text_field(trim($_POST['download_server'])),
sanitize_text_field(trim($_POST['custom_api_server'])), sanitize_text_field(trim($_POST['custom_api_server'])),
sanitize_text_field(trim($_POST['custom_download_server'])) sanitize_text_field(trim($_POST['custom_download_server']))
); );
@ -192,15 +199,11 @@ EOT;
private static function set_wp_option( private static function set_wp_option(
$community = 0, $community = 0,
$api_server = 'api.w.org.ibadboy.net',
$download_server = 'd.w.org.ibadboy.net',
$custom_api_server = '', $custom_api_server = '',
$custom_download_server = '' $custom_download_server = ''
) { ) {
$options = array(); $options = array();
$options['community'] = (int) $community; $options['community'] = (int) $community;
$options['api_server'] = $api_server;
$options['download_server'] = $download_server;
$options['custom_api_server'] = $custom_api_server; $options['custom_api_server'] = $custom_api_server;
$options['custom_download_server'] = $custom_download_server; $options['custom_download_server'] = $custom_download_server;
update_option("wp_china_yes_options", $options); update_option("wp_china_yes_options", $options);

View file

@ -16,8 +16,6 @@
</el-header> </el-header>
<el-main> <el-main>
<el-divider></el-divider> <el-divider></el-divider>
<el-tabs tab-position="right" style="height: 520px;">
<el-tab-pane label="插件设置">
<el-container> <el-container>
<el-main class="no_top_main_box"> <el-main class="no_top_main_box">
<el-form ref="mirrors_form" :model="mirrors_form" <el-form ref="mirrors_form" :model="mirrors_form"
@ -25,29 +23,27 @@
style="width: 342px;"> style="width: 342px;">
<el-card class="box-card" shadow="hover"> <el-card class="box-card" shadow="hover">
<div slot="header"> <div slot="header">
<span>使用社区源</span> <span>使用社区仓库</span>
</div> </div>
<el-form-item label="选择社区源"> <el-form-item label="选择仓库源">
<el-select v-model="mirrors_form.community" <el-radio-group v-model="mirrors_form.community">
@change="changeServer" <el-tooltip class="item" effect="dark"
placeholder="请选择社区源"> content="更新的技术、更快的速度、更佳的负载能力"
<el-option v-for="(item,index) in external_api.server" placement="top-start">
:label="item.name" <el-radio :label="0">主源</el-radio>
:value="item.id"></el-option> </el-tooltip>
</el-select> <el-tooltip class="item" effect="dark"
content="不求新颖但求稳定,力求高可用"
placement="top-start">
<el-radio :label="1">备源</el-radio>
</el-tooltip>
</el-radio-group>
</el-form-item> </el-form-item>
<el-alert
:title="server_desc"
type="info"
:closable="false"
style="width: 422px; margin-left: 20px;"
show-icon>
</el-alert>
</el-card> </el-card>
<el-card class="box-card" shadow="hover"> <el-card class="box-card" shadow="hover">
<div slot="header"> <div slot="header">
<span>自定义源</span> <span>自定义源</span>
<span style="font-size: 12px; margin-left: 10px;">若配置自定义源则会覆盖社区源</span> <span style="font-size: 12px; margin-left: 10px;">若配置自定义源则会覆盖社区仓库源</span>
<el-link href="https://www.ibadboy.net/archives/3349.html" <el-link href="https://www.ibadboy.net/archives/3349.html"
style="float: right;" style="float: right;"
type="primary" type="primary"
@ -79,17 +75,6 @@
</el-form> </el-form>
</el-main> </el-main>
</el-container> </el-container>
</el-tab-pane>
<!--
<el-tab-pane label="贡献者名单">
</el-tab-pane>
<el-tab-pane label="捐助者名单">
</el-tab-pane>
-->
<el-tab-pane label="广告列表">
</el-tab-pane>
</el-tabs>
</el-main> </el-main>
<el-divider></el-divider> <el-divider></el-divider>
<el-footer> <el-footer>
@ -120,7 +105,6 @@
data() { data() {
return { return {
external_api: {}, external_api: {},
server_desc: '',
token: { token: {
get_config: '', get_config: '',
set_config: '' set_config: ''
@ -129,19 +113,10 @@
community: '0', community: '0',
custom_api_server: '', custom_api_server: '',
custom_download_server: '', custom_download_server: '',
api_server: '',
download_server: '',
} }
} }
}, },
methods: { methods: {
changeServer() {
let server = this.external_api.server[this.mirrors_form.community];
this.server_desc = server.desc;
this.mirrors_form.api_server = server.api_server;
this.mirrors_form.download_server = server.download_server;
},
getConfig() { getConfig() {
let vm = this; let vm = this;
let data = new FormData(); let data = new FormData();
@ -154,7 +129,6 @@
axios.get('https://wp-china-yes.ibadboy.net') axios.get('https://wp-china-yes.ibadboy.net')
.then(function (response) { .then(function (response) {
vm.external_api = response.data; vm.external_api = response.data;
vm.changeServer();
}) })
.catch(function (error) { .catch(function (error) {
vm.$message({ vm.$message({
@ -191,8 +165,6 @@
data.append('community', vm.mirrors_form.community); data.append('community', vm.mirrors_form.community);
data.append('custom_api_server', vm.mirrors_form.custom_api_server); data.append('custom_api_server', vm.mirrors_form.custom_api_server);
data.append('custom_download_server', vm.mirrors_form.custom_download_server); data.append('custom_download_server', vm.mirrors_form.custom_download_server);
data.append('api_server', vm.mirrors_form.api_server);
data.append('download_server', vm.mirrors_form.download_server);
axios.post(root_url + 'wp-admin/admin-ajax.php', data) axios.post(root_url + 'wp-admin/admin-ajax.php', data)
.then(function (response) { .then(function (response) {