Commit 81b23655 by 孙龙

up

parent c6fae1f3
<?php
namespace App\Exceptions;
class MicroException extends \Exception{
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class MicroServiceInfoModel extends Model{
protected $connection = 'microservice'; //库名
protected $table = 'service_info';
protected $primaryKey = 'id'; //设置id
protected $guarded = ['id']; //设置字段黑名单
public $timestamps = true;
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
protected $dateFormat = 'Y-m-d H:i:s';
public function fromDateTime($value){
return strtotime(parent::fromDateTime($value));
}
public function service_http_rule()
{
return $this->hasOne(\App\Model\ServiceHttpRuleModel::class,"service_id","id");
}
public function service_access_control()
{
return $this->hasOne(\App\Model\ServiceAccessControlModel::class,"service_id","id");
}
public function service_load_balance()
{
return $this->hasOne(\App\Model\ServiceLoadBalanceModel::class,"service_id","id");
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class ServiceAccessControlModel extends Model{
protected $connection = 'microservice'; //库名
protected $table = 'service_access_control';
protected $primaryKey = 'id'; //设置id
protected $guarded = ['id']; //设置字段黑名单
public $timestamps = false;
const CREATED_AT = null;
const UPDATED_AT = null;
protected $dateFormat = 'Y-m-d H:i:s';
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class ServiceHttpRuleModel extends Model{
protected $connection = 'microservice'; //库名
protected $table = 'service_http_rule';
protected $primaryKey = 'id'; //设置id
protected $guarded = ['id']; //设置字段黑名单
public $timestamps = false;
const CREATED_AT = null;
const UPDATED_AT = null;
protected $dateFormat = 'Y-m-d H:i:s';
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class ServiceLoadBalanceModel extends Model{
protected $connection = 'microservice'; //库名
protected $table = 'service_load_balance';
protected $primaryKey = 'id'; //设置id
protected $guarded = ['id']; //设置字段黑名单
public $timestamps = false;
const CREATED_AT = null;
const UPDATED_AT = null;
protected $dateFormat = 'Y-m-d H:i:s';
}
\ No newline at end of file
layui.use(['form', 'table', 'laydate'], function(){
var form = layui.form;
var table = layui.table;
form.render();
form.on('submit(formDemo)', function(data) {
console.log(data)
$.ajax({
url : "/ajax/addMicroService",
type: 'post',
data: data.field,
success: function(resp) {
console.log(resp)
if (resp.err_code == 0) {
layer.msg(resp.err_msg);
window.location.href="/web/microServicesList"
return false;
}
layer.alert(resp.err_msg);
}
})
return false;
});
var enable_tool = function (title,content,url,datax){
layer.open({
title: title,
content: content,
btn: ['确认', '取消'],
yes: function(index) {
$.ajax({
url : url,
type: 'post',
data: datax,
success: function(resp) {
if (resp.err_code == 0) {
layer.msg(resp.err_msg);
// renderTable(); // 重新加载table
$('.search').trigger("click"); // 触发搜索按钮
if(typeof resp.data.redictUrl != "undefined"){
window.location.href=resp.data.redictUrl;
}
return false;
}
layer.alert(resp.err_msg);
},
error: function(err) {
console.log(err)
}
})
layer.msg(title+'中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
return false;
},
cancel: function(index) {
layer.close(index);
}
})
}
//监听工具条
table.on('tool(list)', function(obj) { //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var tr = obj.tr; //获得当前行 tr 的 DOM 对象(如果有的话)
if (layEvent == "enable"){
title = '启用模板';
content = '确定启用该模板?';
url = '/ajax/template_status';
datax = {id:data.id,status:data.status}
enable_tool(title,content,url,datax);
}else if (layEvent == "forbid"){
title = '禁用模板';
content = '确定禁用该模板?';
url = '/ajax/template_status';
datax = {id:data.id,status:data.status}
enable_tool(title,content,url,datax);
}else if(layEvent == "copy"){
title = '复制模板';
content = '确定要复制该模板?';
url = '/ajax/copy_template';
datax = {t_id:data.id}
enable_tool(title,content,url,datax);
}else if(layEvent == "push"){
title = '推送模板信息到erp';
content = '确定推送?';
url = '/ajax/push_template_erp';
datax = {t_id:data.id}
enable_tool(title,content,url,datax);
}
})
//头工具栏事件
table.on('toolbar(list)', function(obj){
var checkStatus = table.checkStatus(obj.config.id);
switch(obj.event){
case 'getCheckData':
window.location.href= "/web/addMicroService?load_type=0"
break;
};
});
//监听单元格编辑
table.on('edit(list)', function(obj){
var value = obj.value //得到修改后的值
,data = obj.data //得到所在行所有键值
,field = obj.field; //得到字段
title = '修改模板名称';
content = '确定修改模板名称?';
url = '/ajax/edit_template_info';
console.log(obj.data)
enable_tool(title,content,url,obj.data)
});
});
\ No newline at end of file
layui.use(['form', 'table', 'laydate'], function(){
var form = layui.form;
var table = layui.table;
form.render();
table.render({
elem: '#list'
,url: '/ajax/ajaxMicroServicesList' //数据接口
,method:'post'
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
,where: {
}
,defaultToolbar:{}
,toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
,cols: [[ //表头
{title: 'ID',field:"id",fixed: 'left', width: 80}
,{field: 'service_name', title: '服务名称',width: 300}
,{field: 'service_desc', title: '服务描述',width: 300}
,{field: 'load_type', title: '类型',templet:"#load_type",width: 80}
,{field: 'create_time', title: '创建时间', sort: true,width: 200}
,{field: 'update_time', title: '更新时间', sort: true,width: 200}
,{ title: '操作', fixed: 'right', toolbar: '#action'}
]]
,limit: 10
,limits: [10, 20, 50,]
});
form.on('submit(load)', function(data) {
//console.log(data)
//执行重载
table.reload('list', {
page: {
curr: 1
},
url: '/ajax/labelList' //数据接口
,where: data.field
});
return false;
});
var enable_tool = function (title,content,url,datax){
layer.open({
title: title,
content: content,
btn: ['确认', '取消'],
yes: function(index) {
$.ajax({
url : url,
type: 'post',
data: datax,
success: function(resp) {
if (resp.err_code == 0) {
layer.msg(resp.err_msg);
// renderTable(); // 重新加载table
//$('.search').trigger("click"); // 触发搜索按钮
window.location.reload()
return false;
}
layer.alert(resp.err_msg);
},
error: function(err) {
console.log(err)
}
})
layer.msg(title+'中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
return false;
},
cancel: function(index) {
layer.close(index);
}
})
}
//监听工具条
table.on('tool(list)', function(obj) { //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var tr = obj.tr; //获得当前行 tr 的 DOM 对象(如果有的话)
if (layEvent == "edit"){
id = data.id
window.location.href="/web/addMicroService?load_type=0&type=edit&id="+id
}else if (layEvent == "del"){
title = '删除服务';
content = "确定要删除`"+data.service_name+"`服务?";
url = '/ajax/delMicroService';
datax = {id:data.id}
enable_tool(title,content,url,datax);
}
})
//头工具栏事件
table.on('toolbar(list)', function(obj){
var checkStatus = table.checkStatus(obj.config.id);
switch(obj.event){
case 'getCheckData':
window.location.href= "/web/addMicroService?load_type=0&type=add"
break;
};
});
});
\ No newline at end of file
<form class="layui-form" method="post">
<div class="layui-form-item">
<label class="layui-form-label">服务名称</label>
<div class="layui-inline" style="width: 50%">
<input type="text" name="service_name" required value="{{isset($microInfo) ? $microInfo->service_name : ''}}" lay-verify="required" placeholder="6-128位字母数字下划线" autocomplete="off" class="layui-input">
</div>
<div class="layui-inline" style="width: 20%">
<span>备注:etcd注册的服务名称前缀</span>
</div>
</div>
<div class=" layui-form">
<label class="layui-form-label">服务描述</label>
<div class="layui-input-block">
<input type="text" name="service_desc" required value="{{isset($microInfo) ? $microInfo->service_desc : ''}}" lay-verify="required" placeholder="最多255个只读 必填" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">接入类型</label>
<div class="layui-inline">
<div class="layui-input-block" style="margin-left:0;">
<select name="rule_type" lay-filter="aihao">
<option @if(isset($microInfo) && $microInfo->service_http_rule->rule_type == 0) selected @endif value="0">url前缀</option>
{{--<option @if(isset($microInfo) && $microInfo->service_http_rule->rule_type == 1) selected @endif value="1" >域名</option>--}}
</select>
</div>
</div>
<div class="layui-inline" style="width: 30%">
<div class="layui-input-block" style="margin-left:0">
<input type="text" name="rule" value="{{isset($microInfo) ? $microInfo->service_http_rule->rule : ''}}" placeholder="路径格式: /user,域名格式:www.text.com" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline" style="width: 40%">
<span>备注:前缀-默认会在paht路径中去除该前缀;域名:</span>
</div>
</div>
<div class="layui-form-item layui-form-text" style="margin:4px 0">
<label class="layui-form-label">URL重写</label>
<div class="layui-input-block">
<textarea name="url_rewrite" class="layui-textarea" placeholder="格式:^/aaa/(.*) /bbb/$1 多条英文下,隔开">{{isset($microInfo) ? $microInfo->service_http_rule->url_rewrite : ''}}</textarea>
</div>
</div>
<div class="layui-form-item layui-form-text" style="margin:4px 0">
<label class="layui-form-label">Header转换</label>
<div class="layui-input-block">
<textarea name="header_transfor" class="layui-textarea" placeholder="header转换支持增加(add)、删除(del)、修改(edit) 格式: add headname headvalue 多条英文下,隔开">{{isset($microInfo) ? $microInfo->service_http_rule->header_transfor : ''}}</textarea>
</div>
</div>
<div class=" layui-form layui-form-text">
<label class="layui-form-label">客户端限流</label>
<div class="layui-input-block">
<input type="text" name="clientip_flow_limit" required value="{{isset($microInfo) ? $microInfo->service_access_control->clientip_flow_limit : 0}}" lay-verify="required" placeholder="0表示不限制" autocomplete="off" class="layui-input">
</div>
</div>
<div class=" layui-form-item layui-form-text">
<label class="layui-form-label">服务端限流</label>
<div class="layui-input-block">
<input type="text" name="service_flow_limit" required value="{{isset($microInfo) ? $microInfo->service_access_control->service_flow_limit : 0}}" lay-verify="required" placeholder="0表示不限制" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">转发方式</label>
<div class="layui-inline">
<input type="radio" name="need_direct_forward" value="0" title="通过内网负载均衡器转发" @if(isset($microInfo) && $microInfo->service_http_rule->need_direct_forward == 0 || (!isset($microInfo))) checked @endif >
<div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon">
</i><div>通过内网负载均衡器转发</div>
</div>
<input type="radio" name="need_direct_forward" value="1" title="不经过负载均衡器,直接转发到外网或者内网" @if(isset($microInfo) && $microInfo->service_http_rule->need_direct_forward == 1) checked @endif >
<div class="layui-unselect layui-form-radio layui-form-radioed">
<i class="layui-anim layui-icon layui-anim-scaleSpring"></i><div>不经过负载均衡器,直接转发到外网或者内网</div>
</div>
</div>
<div class="layui-inline" style="width: 20%">
<input type="text" name="direct_forward_url" value="{{isset($microInfo) ? $microInfo->service_http_rule->direct_forward_url : ''}}" placeholder="直接转发的url地址" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">轮询方式</label>
<div class="layui-inline">
<input type="radio" name="round_type" value="0" title="随机" @if(isset($microInfo) && $microInfo->service_load_balance->round_type == 0) checked @endif >
<div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon">
</i><div>随机</div>
</div>
<input type="radio" name="round_type" value="1" title="轮询" @if(isset($microInfo) && $microInfo->service_load_balance->round_type == 1) checked @endif >
<div class="layui-unselect layui-form-radio layui-form-radioed">
<i class="layui-anim layui-icon layui-anim-scaleSpring"></i><div>轮询</div>
</div>
<input type="radio" name="round_type" value="2" title="加权轮询" @if(isset($microInfo) && $microInfo->service_load_balance->round_type == 2 || (!isset($microInfo))) checked @endif >
<div class="layui-unselect layui-form-radio layui-form-radioed">
<i class="layui-anim layui-icon layui-anim-scaleSpring"></i>
<div>加权轮询</div>
</div>
<input type="radio" name="round_type" value="3" title="ip_hash" @if(isset($microInfo) && $microInfo->service_load_balance->round_type == 3) checked @endif >
<div class="layui-unselect layui-form-radio layui-form-radioed">
<i class="layui-anim layui-icon layui-anim-scaleSpring"></i>
<div>ip_hash</div>
</div>
</div>
<div class="layui-inline" style="width: 20%">
<span>备注:优先推荐加权轮询</span>
</div>
</div>
<input type="hidden" name="load_type" value="{{request()->input("load_type",0)}}">
<input type="hidden" name="type" value="{{request()->input("type","add")}}">
<input type="hidden" name="id" value="{{request()->input("id",0)}}">
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" type="submit" lay-submit lay-filter="formDemo">提交</button>
</div>
</div>
</form>
\ No newline at end of file
@if (session('showTemplateerror'))
<div class="alert alert-success">
{{ session('showTemplateerror') }}
</div>
@endif
<table id="list" lay-filter="list"></table>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="getCheckData">添加http服务</button>
</div>
</script>
<script type="text/html" id="action">
<a title="编辑" class="btn btn-xs btn-outline btn-info" lay-event="edit">编辑</a>
<a title="删除" class="btn btn-xs btn-outline btn-info" lay-event="del">删除</a>
</script>
<script type="text/html" id="load_type">
@{{# if (d.load_type == 0) { }}
http
@{{# }else if (d.load_type == 1) { }}
tcp
@{{# }else if (d.load_type == 2) { }}
grpc
@{{# } }}
</script>
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 sign in to comment