Browse Source

1.修改默认图标位置

2.添加链接时可上传图标或手工输入图标链接
pull/117/head
wmgang@qq.com 1 year ago
parent
commit
3df736df37
  1. 44
      class/Api.php
  2. 13
      controller/api.php
  3. 2
      controller/click.php
  4. 14
      templates/admin/add_link.php
  5. 23
      templates/admin/static/embed.js
  6. 0
      upload/default.png

44
class/Api.php

@ -204,7 +204,7 @@ class Api { @@ -204,7 +204,7 @@ class Api {
/**
* 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);
$fid = intval($fid);
//检测链接是否合法
@ -225,7 +225,8 @@ class Api { @@ -225,7 +225,8 @@ class Api {
'description' => htmlspecialchars($description,ENT_QUOTES),
'add_time' => time(),
'weight' => $weight,
'property' => $property
'property' => $property,
'font_icon' => $font_icon
];
//插入数据库
$re = $this->db->insert('on_links',$data);
@ -531,6 +532,45 @@ class Api { @@ -531,6 +532,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链接进行备份
*/

13
controller/api.php

@ -107,8 +107,9 @@ function add_link($api){ @@ -107,8 +107,9 @@ function add_link($api){
$description = empty($_POST['description']) ? '' : $_POST['description'];
$weight = empty($_POST['weight']) ? 0 : intval($_POST['weight']);
$property = empty($_POST['property']) ? 0 : 1;
$api->add_link($token,$fid,$title,$url,$description,$weight,$property,$url_standby);
$font_icon = empty($_POST['font_icon']) ? '' : $_POST['font_icon'];
$api->add_link($token,$fid,$title,$url,$description,$weight,$property,$url_standby,$font_icon);
}
/**
@ -239,6 +240,14 @@ function upload($api){ @@ -239,6 +240,14 @@ function upload($api){
$type = $_GET['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) {
//获取token

2
controller/click.php

@ -13,7 +13,7 @@ if(empty($id)) { @@ -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
]);

14
templates/admin/add_link.php

@ -30,6 +30,20 @@ @@ -30,6 +30,20 @@
</div>
<!-- 备用链接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">
<label class="layui-form-label">链接名称</label>
<div class="layui-input-block">

23
templates/admin/static/embed.js

@ -90,7 +90,7 @@ layui.use(['element','table','layer','form','upload','iconHhysFa'], function(){ @@ -90,7 +90,7 @@ layui.use(['element','table','layer','form','upload','iconHhysFa'], function(){
,{field: 'font_icon', title: '图标', width:60, templet:function(d){
if(d.font_icon==null)
{
return '<img src="static/images/default.png" width="28" height="28">';
return '<img src="upload/default.png" width="28" height="28">';
}
else
{
@ -733,6 +733,27 @@ layui.use(['element','table','layer','form','upload','iconHhysFa'], function(){ @@ -733,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() {

0
static/images/default.png → upload/default.png

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Loading…
Cancel
Save