Commit 448f62bf authored by tufengqi's avatar tufengqi

新增BETA GA切换功能

parent 2f46210b
...@@ -100,12 +100,28 @@ class Application extends Component ...@@ -100,12 +100,28 @@ class Application extends Component
} }
$app_self_config = Yii::$app->fpf->getConfig(self::APP_SELF_CONFIG_PREFIX . APP_NAME, 'common'); $app_self_config = Yii::$app->fpf->getConfig(self::APP_SELF_CONFIG_PREFIX . APP_NAME, 'common');
$user_ip = Yii::$app->request->userIP; $user_ip = Yii::$app->request->userIP;
$host_name = Yii::$app->request->getHostName();
$is_online_host = $this->isOnlineHost($host_name);
if ($this->isAllowIp($user_ip)) { if ($this->isAllowIp($user_ip)) {
\Yii::$app->response->headers->add('Content-type', 'text/html'); \Yii::$app->response->headers->add('Content-type', 'text/html');
// 开关开启,用户IP是公司IP,内外IP,允许打开cookie编辑 // 开关开启,用户IP是公司IP,内外IP,允许打开cookie编辑
include(__DIR__ . '/views/CookieEdit.php'); include(__DIR__ . '/views/CookieEdit.php');
} }
} }
private function isOnlineHost($host_name)
{
if (preg_match("/(.test|.dev|.local)$/", $host_name)) {
$ret = false;
} else if (preg_match("/^(test.|dev.|local.)/", $host_name)) {
$ret = false;
} else if (preg_match("/(.test.|.dev.|.local.)/", $host_name)) {
$ret = false;
} else {
$ret = true;
}
return $ret;
}
private function isAllowIp($user_ip) private function isAllowIp($user_ip)
{ {
$company_ip_list = Yii::$app->fpf->getConfig('company_ip_list', 'ip'); $company_ip_list = Yii::$app->fpf->getConfig('company_ip_list', 'ip');
......
...@@ -59,34 +59,71 @@ ...@@ -59,34 +59,71 @@
table.fashiontable tr:hover { table.fashiontable tr:hover {
background: #f5f5f5; background: #f5f5f5;
} }
<?php
if ($is_online_host) {
$witdh = '260';
} else {
$witdh = '460';
}
?>
/* ========= table表格 ===========}}} */ /* ========= table表格 ===========}}} */
.cookie_table .dataintable th{height:40px;line-height:40px;} .cookie_table .dataintable th{height:40px;line-height:40px;}
.cookie_table .dataintable td,.cookie_table .dataintable th{text-align:center;padding:10px;color:#666666;} .cookie_table .dataintable td,.cookie_table .dataintable th{text-align:center;padding:10px;color:#666666;}
.cookie_table td input{height:30px;width:460px;padding:0 10px;border:1px solid #d6d6d6;} .cookie_table td input{height:30px;width:<?php echo $witdh; ?>px;padding:0 10px;border:1px solid #d6d6d6;}
.cookie_table tr{padding:10px;} .cookie_table tr{padding:10px;}
.btn_list{overflow:hidden;padding:5px;} .btn_list{overflow:hidden;padding:5px;}
.btn_list span{padding:2px 10px;background:#dddddd;cursor:pointer;color:#666666;border:1px solid #999999;} .btn_list span{padding:2px 10px;background:#dddddd;cursor:pointer;color:#666666;border:1px solid #999999;}
.notice_box{ .notice_box{
height:30px;display:none; height:30px;
line-height:30px;background:#fefcee; line-height:30px;background:#fefcee;
border:1px solid #f3d995;color:#df9c1f;text-align:center; border:1px solid #f3d995;color:#df9c1f;text-align:center;
} }
.btn_list span:hover{background:#ccc;}
.text_input .btn_list .checked{background:#66ff33;color:#ffffff;border:1px solid #39e600}
</style> </style>
<script src="https://www.zhaobi.com/static/jquery-3.2.1.min.js"></script> <script src="https://www.zhaobi.com/static/jquery-3.2.1.min.js"></script>
</head> </head>
<body> <body>
<div class="content"> <div class="content">
<div class="cookie_table"> <div class="cookie_table">
<div class="notice_box"><span></span></div> <div class="notice_box"><span><?php
if (VERSION_VALUE) {
$patt = "/(file|cookie)-([a-zA-Z0-9]+)/";
if (preg_match($patt, VERSION_VALUE, $result)) {
$type = $result[1];
$version = $result[2];
$type_desc = '';
if ('file' === $type) {
$type_desc = '文件定义的版本号';
} else if ('cookie' === $type) {
$type_desc = 'cookie版本';
}
} else {
echo '您当前处于本地开发环境,无版本目录';
}
echo '当前访问的是' . $type_desc . ", 版本号为" . $version;
} else {
echo '您当前处于本地开发环境,无版本目录';
}
?></span></div>
<table class="dataintable"> <table class="dataintable">
<tr> <tr>
<th width="50%">COOKIE名</th><th width="50%">COOKIE值(jira项目名-项目ID,如: TRADE-11)</th> <th width="50%">COOKIE名</th><th width="50%">COOKIE值(jira项目名-项目ID,如: TRADE-11)</th>
</tr> </tr>
<tr> <tr>
<td><?php echo VERSION_KEY; ?></td> <td><?php echo VERSION_KEY; ?></td>
<td> <td class="text_input">
<input type="text" name="<?php echo VERSION_KEY; ?>"> <input type="text" name="<?php echo VERSION_KEY; ?>" value="<?php echo $version; ?>">
<?php if ($is_online_host) { ?>
<span class="btn_list" id="check_one">
&nbsp;&nbsp;
<span class="submit_beta check_item" data-val="beta">BETA</span>
&nbsp;&nbsp;
<span class="return_ga check_item" data-val="ga">GA</span>
</span>
<?php
}
?>
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -113,7 +150,7 @@ ...@@ -113,7 +150,7 @@
<script> <script>
$(".submit_cookie").on("click",function(){ $(".submit_cookie").on("click",function(){
$(".notice_box").show().find("span").html("查询处理结果中。。。"); $(".notice_box").show().find("span").html("查询处理结果中。。。");
var cookie_val = $("input[name='<?php echo VERSION_KEY; ?>']").val(); var cookie_val = $.trim($("input[name='<?php echo VERSION_KEY; ?>']").val());
var script = document.createElement('script'); var script = document.createElement('script');
script.type = 'text/javascript'; script.type = 'text/javascript';
script.src = location.href+"&set_cookie_val="+cookie_val; script.src = location.href+"&set_cookie_val="+cookie_val;
...@@ -129,7 +166,7 @@ $(".submit_cookie").on("click",function(){ ...@@ -129,7 +166,7 @@ $(".submit_cookie").on("click",function(){
// 在这里,做想做的事。。。 // 在这里,做想做的事。。。
if(wpoInfo['fpf-version']){ if(wpoInfo['fpf-version']){
var str = wpoInfo['fpf-version']; var str = wpoInfo['fpf-version'];
var patt = /(file|cookie)-([a-zA-Z0-9-]+)/; var patt = /(file|cookie)-([a-zA-Z0-9]+)/;
var result; var result;
if ((result = patt.exec(str)) != null) { if ((result = patt.exec(str)) != null) {
var type = result[1]; var type = result[1];
...@@ -140,7 +177,11 @@ $(".submit_cookie").on("click",function(){ ...@@ -140,7 +177,11 @@ $(".submit_cookie").on("click",function(){
}else if('cookie' == type){ }else if('cookie' == type){
type_desc = 'cookie版本'; type_desc = 'cookie版本';
} }
$(".notice_box span").html("当前访问的是"+type_desc+", 版本号为"+version); var warm_text = "";
if(cookie_val && cookie_val != version){
var warm_text = '服务端可能不存在您设置的版本目录"'+cookie_val+'"';
}
$(".notice_box span").html(warm_text+" "+"当前访问的是"+type_desc+", 版本号为"+version);
}else{ }else{
$(".notice_box span").html("未知的版本类型:"+str); $(".notice_box span").html("未知的版本类型:"+str);
} }
...@@ -155,6 +196,23 @@ $(".return_page").on("click",function(){ ...@@ -155,6 +196,23 @@ $(".return_page").on("click",function(){
link = link.replace(/cookie_edit=(1|true)/i,""); link = link.replace(/cookie_edit=(1|true)/i,"");
location.href = link; location.href = link;
}); });
<?php if ($is_online_host) { ?>
var history_version = $(".text_input input").val();
$("#check_one .check_item").on("click",function(){
if($(this).hasClass("checked")){
$(this).removeClass("checked");
$(".text_input input").val(history_version);
}else{
$(this).siblings().removeClass("checked");
$(this).addClass("checked");
var version = $(this).attr("data-val");
$(".text_input input").val(version);
}
});
<?php
}
?>
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment