Browse Source

Merge branch 'dev' of github.com:helloxz/onenav into dev

pull/119/head
xiaoz 2 years ago
parent
commit
7cde2673d2
  1. 49
      class/Api.php
  2. 18
      controller/api.php
  3. 2
      controller/click.php
  4. BIN
      db/onenav.simple.db3
  5. 14
      templates/admin/add_link.php
  6. 14
      templates/admin/edit_link.php
  7. 34
      templates/admin/static/embed.js
  8. BIN
      upload/default.png

49
class/Api.php

@ -206,7 +206,7 @@ class Api {
/** /**
* name:添加链接 * name:添加链接
*/ */
public function add_link($token,$fid,$title,$url,$description = '',$weight = 0,$property = 0,$url_standby = ''){ public function add_link($token,$fid,$title,$url,$description = '',$weight = 0,$property = 0,$url_standby = '',$font_icon=''){
$this->auth($token); $this->auth($token);
$fid = intval($fid); $fid = intval($fid);
//检测链接是否合法 //检测链接是否合法
@ -227,7 +227,8 @@ class Api {
'description' => htmlspecialchars($description,ENT_QUOTES), 'description' => htmlspecialchars($description,ENT_QUOTES),
'add_time' => time(), 'add_time' => time(),
'weight' => $weight, 'weight' => $weight,
'property' => $property 'property' => $property,
'font_icon' => $font_icon
]; ];
//插入数据库 //插入数据库
$re = $this->db->insert('on_links',$data); $re = $this->db->insert('on_links',$data);
@ -533,6 +534,45 @@ class Api {
} }
} }
} }
/**
* 图标上传
* type:上传类型
*/
public function uploadImages($token,$type){
$this->auth($token);
if ($_FILES["file"]["error"] > 0)
{
$this->err_msg(-1015,'File upload failed!');
}
else
{
//根据时间生成文件名
$filename = $_FILES["file"]["name"];
//获取文件后缀
$suffix = explode('.',$filename);
$suffix = strtolower(end($suffix));
//临时文件位置
$temp = $_FILES["file"]["tmp_name"];
if( $suffix != 'ico' && $suffix != 'jpg' && $suffix != 'png' && $suffix != 'bmp' ) {
//删除临时文件
unlink($filename);
$this->err_msg(-1014,'Unsupported file suffix name!');
}
$newfilename='upload/'.time().'.'.$suffix;
if( copy($temp,$newfilename) ) {
$data = [
'code' => 0,
'file_name' => $newfilename
];
exit(json_encode($data));
}
}
}
/** /**
* 导出HTML链接进行备份 * 导出HTML链接进行备份
*/ */
@ -570,7 +610,7 @@ class Api {
/** /**
* name:修改链接 * name:修改链接
*/ */
public function edit_link($token,$id,$fid,$title,$url,$description = '',$weight = 0,$property = 0,$url_standby = ''){ public function edit_link($token,$id,$fid,$title,$url,$description = '',$weight = 0,$property = 0,$url_standby = '',$font_icon = ''){
$this->auth($token); $this->auth($token);
$fid = intval($fid); $fid = intval($fid);
//检测链接是否合法 //检测链接是否合法
@ -596,7 +636,8 @@ class Api {
'description' => htmlspecialchars($description,ENT_QUOTES), 'description' => htmlspecialchars($description,ENT_QUOTES),
'up_time' => time(), 'up_time' => time(),
'weight' => $weight, 'weight' => $weight,
'property' => $property 'property' => $property,
'font_icon' => $font_icon
]; ];
//插入数据库 //插入数据库
$re = $this->db->update('on_links',$data,[ 'id' => $id]); $re = $this->db->update('on_links',$data,[ 'id' => $id]);

18
controller/api.php

@ -107,8 +107,9 @@ function add_link($api){
$description = empty($_POST['description']) ? '' : $_POST['description']; $description = empty($_POST['description']) ? '' : $_POST['description'];
$weight = empty($_POST['weight']) ? 0 : intval($_POST['weight']); $weight = empty($_POST['weight']) ? 0 : intval($_POST['weight']);
$property = empty($_POST['property']) ? 0 : 1; $property = empty($_POST['property']) ? 0 : 1;
$font_icon = empty($_POST['font_icon']) ? '' : $_POST['font_icon'];
$api->add_link($token,$fid,$title,$url,$description,$weight,$property,$url_standby);
$api->add_link($token,$fid,$title,$url,$description,$weight,$property,$url_standby,$font_icon);
} }
/** /**
@ -128,8 +129,9 @@ function edit_link($api){
$description = empty($_POST['description']) ? '' : $_POST['description']; $description = empty($_POST['description']) ? '' : $_POST['description'];
$weight = empty($_POST['weight']) ? 0 : intval($_POST['weight']); $weight = empty($_POST['weight']) ? 0 : intval($_POST['weight']);
$property = empty($_POST['property']) ? 0 : 1; $property = empty($_POST['property']) ? 0 : 1;
$font_icon = empty($_POST['font_icon']) ? '' : $_POST['font_icon'];
$api->edit_link($token,$id,$fid,$title,$url,$description,$weight,$property,$url_standby);
$api->edit_link($token,$id,$fid,$title,$url,$description,$weight,$property,$url_standby,$font_icon);
} }
@ -239,6 +241,14 @@ function upload($api){
$type = $_GET['type']; $type = $_GET['type'];
$api->upload($token,$type); $api->upload($token,$type);
} }
// 上传图标
function uploadImages($api){
//获取token
$token = empty( $_POST['token'] ) ? $_GET['token'] : $_POST['token'];
//获取上传类型
$type = $_GET['type'];
$api->uploadImages($token,$type);
}
//书签导入 //书签导入
function imp_link($api) { function imp_link($api) {
//获取token //获取token

2
controller/click.php

@ -13,7 +13,7 @@ if(empty($id)) {
} }
//查询链接信息 //查询链接信息
$link = $db->get('on_links',['id','fid','url','url_standby','property','click','title','description'],[ $link = $db->get('on_links',['id','fid','url','url_standby','property','click','title','description','font_icon'],[
'id' => $id 'id' => $id
]); ]);

BIN
db/onenav.simple.db3

Binary file not shown.

14
templates/admin/add_link.php

@ -30,6 +30,20 @@
</div> </div>
<!-- 备用链接END --> <!-- 备用链接END -->
<div class="layui-form-item">
<label class="layui-form-label">图标</label>
<div class="layui-input-block">
<button type="button" id = "iconUpload" name="iconUpload" class="layui-btn"><i class="layui-icon">&#xe67c;</i>上传图标</button>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">图标链接</label>
<div class="layui-input-block">
<input type="url" id = "font_icon" name="font_icon" placeholder="请输入图标链接,如果没有,请留空" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">链接名称</label> <label class="layui-form-label">链接名称</label>
<div class="layui-input-block"> <div class="layui-input-block">

14
templates/admin/edit_link.php

@ -38,6 +38,20 @@
</div> </div>
<!-- 备用链接END --> <!-- 备用链接END -->
<div class="layui-form-item">
<label class="layui-form-label">图标</label>
<div class="layui-input-block">
<button type="button" id = "iconUpload" name="iconUpload" class="layui-btn"><i class="layui-icon">&#xe67c;</i>上传图标</button>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">图标链接</label>
<div class="layui-input-block">
<input type="url" id = "font_icon" value = "<?php echo $link['font_icon']; ?>" name="font_icon" placeholder="请输入图标链接,如果没有,请留空" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">链接名称</label> <label class="layui-form-label">链接名称</label>
<div class="layui-input-block"> <div class="layui-input-block">

34
templates/admin/static/embed.js

@ -21,6 +21,9 @@ layui.use(['element','table','layer','form','upload','iconHhysFa'], function(){
,page: true //开启分页 ,page: true //开启分页
,cols: [[ //表头 ,cols: [[ //表头
{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'} {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
,{field: 'font_icon', title: '图标', width:60, templet: function(d){
return '<i class="fa-lg '+d.font_icon+'"></i>';
}}
,{field: 'name', title: '分类名称', width:160} ,{field: 'name', title: '分类名称', width:160}
,{field: 'fname', title: '父级分类', width:160} ,{field: 'fname', title: '父级分类', width:160}
,{field: 'add_time', title: '添加时间', width:160, sort: true,templet:function(d){ ,{field: 'add_time', title: '添加时间', width:160, sort: true,templet:function(d){
@ -84,6 +87,16 @@ layui.use(['element','table','layer','form','upload','iconHhysFa'], function(){
,cols: [[ //表头 ,cols: [[ //表头
{type:'checkbox'} //开启复选框 {type:'checkbox'} //开启复选框
,{field: 'id', title: 'ID', width:80, sort: true} ,{field: 'id', title: 'ID', width:80, sort: true}
,{field: 'font_icon', title: '图标', width:60, templet:function(d){
if(d.font_icon==null)
{
return '<img src="upload/default.png" width="28" height="28">';
}
else
{
return '<img src="'+d.font_icon+'" width="28" height="28">';
}
}}
// ,{field: 'fid', title: '分类ID',sort:true, width:90} // ,{field: 'fid', title: '分类ID',sort:true, width:90}
,{field: 'category_name', title: '所属分类',sort:true,width:120} ,{field: 'category_name', title: '所属分类',sort:true,width:120}
,{field: 'url', title: 'URL',width:140,templet:function(d){ ,{field: 'url', title: 'URL',width:140,templet:function(d){
@ -720,6 +733,27 @@ layui.use(['element','table','layer','form','upload','iconHhysFa'], function(){
} }
}); });
upload.render({
elem: '#iconUpload' //绑定元素
,url: 'index.php?c=api&method=uploadImages' //上传接口
,accept:'file'
,exts: 'ico|jpg|png|bmp'
,done: function(res){
//console.log(res);
//上传完毕回调
if( res.code == 0 ) {
$("#font_icon").val(res.file_name);
}
else if( res.code < 0) {
layer.msg(res.err_msg, {icon: 5});
layer.close();
}
}
,error: function(){
//请求异常回调
}
});
}); });
function get_link_info() { function get_link_info() {

BIN
upload/default.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Loading…
Cancel
Save