提交 0bedabe1 编写于 作者: D devil_gong

附件组件优化

上级 46c477c1
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\api\controller;
use think\Db;
use app\service\ResourcesService;
/**
* 开发测试
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class Devtest extends Common
{
/**
* 构造方法
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-11-30
* @desc description
*/
public function __construct()
{
parent::__construct();
}
/**
* 附件
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-02-22T16:50:32+0800
*/
public function Index()
{
if(input('pwd') != 'shopxo520')
{
die('非法访问');
}
$count = 0;
$success = 0;
$error = 0;
$path_all = [
'video' => __MY_ROOT_PUBLIC__.'static/upload/video/',
'file' => __MY_ROOT_PUBLIC__.'static/upload/file/',
'image' => __MY_ROOT_PUBLIC__.'static/upload/images/',
];
foreach($path_all as $type=>$path)
{
$path = GetDocumentRoot() . (substr($path, 0, 1) == "/" ? "":"/") . $path;
// 从磁盘获取文件
$files = $this->GetDirFilesList($path, $type, $path);
if(!empty($files))
{
$count += count($files);
foreach($files as $v)
{
$temp = Db::name('Attachment')->where(['title'=>$v['title'], 'hash'=>$v['hash']])->find();
if(empty($temp))
{
$ret = ResourcesService::AttachmentAdd($v);
if($ret['code'] == 0)
{
$success++;
} else {
$error++;
}
} else {
$success++;
}
}
}
}
echo '总数['.$count.'], 成功['.$success.'], 失败['.$error.']';
}
/**
* 遍历获取目录下的指定类型的文件
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-01-17T23:24:59+0800
* @param [string] $path [路径地址]
* @param [string] $type [允许的文件]
* @param [array] &$files [数据]
* @return [array] [数据]
*/
private function GetDirFilesList($path, $type, $path_old, &$files = array())
{
if(!is_dir($path)) return null;
if(substr($path, strlen($path) - 1) != '/') $path .= '/';
$handle = opendir($path);
$document_root = GetDocumentRoot();
while(false !== ($file = readdir($handle)))
{
if($file != 'index.html' && $file != '.' && $file != '..' && substr($file, 0, 1) != '.')
{
$path2 = $path . $file;
if(is_dir($path2))
{
$this->GetDirFilesList($path2, $type, $path_old, $files);
} else {
$url = ResourcesService::AttachmentPathHandle(substr($path2, strlen($document_root)));
$title = substr($url, strripos($url, '/')+1);
$root_path = ROOT.'public'.$url;
$path_type = str_replace($path_old, '', $root_path);
$files[] = array(
'url' => $url,
'original' => $title,
'title' => $title,
'type' => $type,
'path_type' => substr($path_type, 0, stripos($path_type, '/')),
'size' => file_exists($root_path) ? filesize($root_path) : 0,
'hash' => file_exists($root_path) ? hash_file('sha256', $root_path, false) : '',
'ext' => substr($title, strripos($title, '.')),
);
}
}
}
return $files;
}
}
?>
\ No newline at end of file
......@@ -210,6 +210,7 @@ class Ueditor extends Common
if(isset($data['state']) && $data['state'] == 'SUCCESS')
{
$data['type'] = $attachment_type;
$data['path_type'] = empty($this->data_request['path_type']) ? 'other' : $this->data_request['path_type'];
$ret = ResourcesService::AttachmentAdd($data);
if($ret['code'] == 0)
{
......@@ -266,11 +267,17 @@ class Ueditor extends Common
'm' => $start,
'n' => $size,
'where' => [
'type' => substr($this->current_action, 4),
'path_type' => input('path_type', 'other'),
['type', '=', substr($this->current_action, 4)],
['path_type', '=', empty($this->data_request['path_type']) ? 'other' : $this->data_request['path_type']]
],
];
// 搜索关键字
if(!empty($this->data_request['keywords']))
{
$params['where'][] = ['original', 'like', '%'.$this->data_request['keywords'].'%'];
}
// 数据初始化
$data = array(
'state' => "没有相关数据",
......@@ -330,6 +337,7 @@ class Ueditor extends Common
if(isset($data['state']) && $data['state'] == 'SUCCESS')
{
$data['type'] = 'remote';
$data['path_type'] = empty($this->data_request['path_type']) ? 'other' : $this->data_request['path_type'];
$ret = ResourcesService::AttachmentAdd($data);
if($ret['code'] != 0)
{
......
......@@ -382,6 +382,9 @@ class PluginsAdminService
}
}
// 删除数据库附件
ResourcesService::AttachmentPathTypeDelete('plugins_'.$params['id']);
// 删除应用文件
self::PluginsResourcesDelete($params['id'], $is_delete_static);
......
......@@ -129,6 +129,11 @@ class ResourcesService
'key_name' => 'original',
'error_msg' => '原名有误',
],
[
'checked_type' => 'empty',
'key_name' => 'path_type',
'error_msg' => '路径标记有误',
],
[
'checked_type' => 'empty',
'key_name' => 'url',
......@@ -158,7 +163,7 @@ class ResourcesService
// 数据组装
$data = [
'path_type' => input('path_type', 'other'),
'path_type' => $params['path_type'],
'original' => empty($params['original']) ? '' : mb_substr($params['original'], -160, null, 'utf-8'),
'title' => $params['title'],
'size' => $params['size'],
......@@ -309,7 +314,7 @@ class ResourcesService
$ret = DataReturn('删除成功', 0);
} else {
$ret = DataReturn('删除失败', -1);
$ret = DataReturn('删除失败', -100);
}
} else {
$ret = DataReturn('没有删除权限', -1);
......@@ -319,7 +324,7 @@ class ResourcesService
{
$ret = DataReturn('删除成功', 0);
} else {
$ret = DataReturn('删除失败', -1);
$ret = DataReturn('删除失败', -100);
}
}
......@@ -336,5 +341,23 @@ class ResourcesService
}
return $ret;
}
/**
* 附件根据标记删除
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-06-25T23:35:27+0800
* @param [string] $path_type [唯一标记]
*/
public static function AttachmentPathTypeDelete($path_type)
{
// 请求参数
if(DB::name('Attachment')->where(['path_type'=>$path_type])->delete() !== false)
{
return DataReturn('删除成功', 0);
}
return DataReturn('删除失败', -100);
}
}
?>
\ No newline at end of file
......@@ -735,4 +735,39 @@ i.file-preview.file-type-psd{
background: rgba(0, 0, 0, 0.3);
color: #fff;
padding: 2px 0;
}
/**
* 右侧小导航
*/
.alignBar{
float:right;
position: relative;
}
/**
* 搜索
*/
.none {
display: none;
}
#search-submit {
background: #eee;
font-size: 12px;
color: #666;
height: 25px;
text-align: center;
cursor: pointer;
padding-left: 15px;
padding-right: 15px;
vertical-align: top;
}
#search-input {
padding: 4px 5px;
}
#search-input, #search-submit {
border-radius: 3px;
border: 1px solid #ccc;
outline: none;
}
\ No newline at end of file
......@@ -22,6 +22,12 @@
<span class="tab focus" data-content-id="upload"><var id="lang_tab_upload"></var></span>
<span class="tab" data-content-id="online"><var id="lang_tab_online"></var></span>
</div>
<div class="alignBar">
<div id="search-container" class="none">
<input type="text" name="keywords" id="search-input" placeholder="其实搜索很简单^_^!" />
<button type="button" id="search-submit">搜索</button>
</div>
</div>
<div id="tabbody" class="tabbody">
<!-- 上传图片 -->
<div id="upload" class="panel focus">
......
......@@ -12,6 +12,7 @@
window.onload = function () {
initTabs();
initAlign();
initButtons();
};
......@@ -42,16 +43,26 @@
domUtils.removeClasses($G(bodyId), 'focus');
}
}
document.getElementById('search-container').setAttribute('class', 'none');
switch (id) {
case 'upload':
uploadFile = uploadFile || new UploadFile('queueList');
break;
case 'online':
document.getElementById('search-container').setAttribute('class', '');
onlineFile = onlineFile || new OnlineFile('fileList');
break;
}
}
/* 初始化搜索点击事件 */
function initAlign(){
domUtils.on($G("search-submit"), 'click', function(e){
onlineFile = new OnlineFile('fileList');
});
}
/* 初始化onok事件 */
function initButtons() {
......@@ -634,7 +645,8 @@
timeout: 100000,
data: utils.extend({
start: this.listIndex,
size: this.listSize
size: this.listSize,
keywords: document.getElementById('search-input').value
}, editor.queryCommandValue('serverparam')),
method: 'get',
onsuccess: function (r) {
......
......@@ -37,62 +37,6 @@
display: block;
}
/* 图片对齐方式 */
.alignBar{
float:right;
margin-top: 5px;
position: relative;
}
.alignBar .algnLabel{
float:left;
height: 20px;
line-height: 20px;
}
.alignBar #alignIcon{
zoom:1;
_display: inline;
display: inline-block;
position: relative;
}
.alignBar #alignIcon span{
float: left;
cursor: pointer;
display: block;
width: 19px;
height: 17px;
margin-right: 3px;
margin-left: 3px;
background-image: url(./images/alignicon.jpg);
}
.alignBar #alignIcon .none-align{
background-position: 0 -18px;
}
.alignBar #alignIcon .left-align{
background-position: -20px -18px;
}
.alignBar #alignIcon .right-align{
background-position: -40px -18px;
}
.alignBar #alignIcon .center-align{
background-position: -60px -18px;
}
.alignBar #alignIcon .none-align.focus{
background-position: 0 0;
}
.alignBar #alignIcon .left-align.focus{
background-position: -20px 0;
}
.alignBar #alignIcon .right-align.focus{
background-position: -40px 0;
}
.alignBar #alignIcon .center-align.focus{
background-position: -60px 0;
}
/* 远程图片样式 */
#remote {
......@@ -708,194 +652,6 @@
background-position: 72px 72px;
}
/* 图片搜索样式 */
#search .searchBar {
width: 100%;
height: 30px;
margin: 10px 0 5px 0;
padding: 0;
}
#search input.text{
width: 150px;
padding: 3px 6px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
-webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
#search input.text:focus {
border-color: #66afe9;
outline: 0;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6);
}
#search input.searchTxt {
margin-left:5px;
padding-left: 5px;
background: #FFF;
width: 300px;
*width: 260px;
height: 21px;
line-height: 21px;
float: left;
dislay: block;
}
#search .searchType {
width: 65px;
height: 28px;
padding:0;
line-height: 28px;
border: 1px solid #d7d7d7;
border-radius: 0;
vertical-align: top;
margin-left: 5px;
float: left;
dislay: block;
}
#search #searchBtn,
#search #searchReset {
display: inline-block;
margin-bottom: 0;
margin-right: 5px;
padding: 4px 10px;
font-weight: 400;
text-align: center;
vertical-align: middle;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
white-space: nowrap;
font-size: 14px;
border-radius: 4px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
vertical-align: top;
float: right;
}
#search #searchBtn {
color: white;
border-color: #285e8e;
background-color: #3b97d7;
}
#search #searchReset {
color: #333;
border-color: #ccc;
background-color: #fff;
}
#search #searchBtn:hover {
background-color: #3276b1;
}
#search #searchReset:hover {
background-color: #eee;
}
#search .msg {
margin-left: 5px;
}
#search .searchList{
width: 100%;
height: 300px;
overflow: hidden;
clear: both;
}
#search .searchList ul{
margin:0;
padding:0;
list-style:none;
clear: both;
width: 100%;
height: 100%;
overflow-x: hidden;
overflow-y: auto;
zoom: 1;
position: relative;
}
#search .searchList li {
list-style:none;
float: left;
display: block;
width: 115px;
margin: 5px 10px 5px 20px;
*margin: 5px 10px 5px 15px;
padding:0;
font-size: 12px;
box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
position: relative;
vertical-align: top;
text-align: center;
overflow: hidden;
cursor: pointer;
filter: alpha(Opacity=100);
-moz-opacity: 1;
opacity: 1;
border: 2px solid #eee;
}
#search .searchList li.selected {
filter: alpha(Opacity=40);
-moz-opacity: 0.4;
opacity: 0.4;
border: 2px solid #00a0e9;
}
#search .searchList li p {
background-color: #eee;
margin: 0;
padding: 0;
position: relative;
width:100%;
height:115px;
overflow: hidden;
}
#search .searchList li p img {
cursor: pointer;
border: 0;
}
#search .searchList li a {
color: #999;
border-top: 1px solid #F2F2F2;
background: #FAFAFA;
text-align: center;
display: block;
padding: 0 5px;
width: 105px;
height:32px;
line-height:32px;
white-space:nowrap;
text-overflow:ellipsis;
text-decoration: none;
overflow: hidden;
word-break: break-all;
}
#search .searchList a:hover {
text-decoration: underline;
color: #333;
}
#search .searchList .clearFloat{
clear: both;
}
#online li .delbtn {
position: absolute;
top: 0;
......@@ -976,4 +732,39 @@
background: rgba(0, 0, 0, 0.3);
color: #fff;
padding: 2px 0;
}
/**
* 右侧小导航
*/
.alignBar{
float:right;
position: relative;
}
/**
* 搜索
*/
.none {
display: none;
}
#search-submit {
background: #eee;
font-size: 12px;
color: #666;
height: 25px;
text-align: center;
cursor: pointer;
padding-left: 15px;
padding-right: 15px;
border-radius: 3px;
vertical-align: top;
}
#search-input {
padding: 4px 5px;
}
#search-input, #search-submit {
border-radius: 3px;
border: 1px solid #ccc;
outline: none;
}
\ No newline at end of file
......@@ -24,17 +24,12 @@
<span class="tab" data-content-id="online"><var id="lang_tab_online"></var></span>
</div>
<div class="alignBar">
<label class="algnLabel"><var id="lang_input_align"></var></label>
<span id="alignIcon">
<span id="noneAlign" class="none-align focus" data-align="none"></span>
<span id="leftAlign" class="left-align" data-align="left"></span>
<span id="rightAlign" class="right-align" data-align="right"></span>
<span id="centerAlign" class="center-align" data-align="center"></span>
</span>
<input id="align" name="align" type="hidden" value="none"/>
<div id="search-container" class="none">
<input type="text" name="keywords" id="search-input" placeholder="其实搜索很简单^_^!" />
<button type="button" id="search-submit">搜索</button>
</div>
</div>
<div id="tabbody" class="tabbody">
<!-- 远程图片 -->
<div id="remote" class="panel">
<div class="top">
......@@ -94,23 +89,6 @@
<div id="online" class="panel">
<div id="imageList"><var id="lang_imgLoading"></var></div>
</div>
<!-- 搜索图片 -->
<div id="search" class="panel">
<div class="searchBar">
<input id="searchTxt" class="searchTxt text" type="text" />
<select id="searchType" class="searchType">
<option value="&s=4&z=0"></option>
<option value="&s=1&z=19"></option>
<option value="&s=2&z=0"></option>
<option value="&s=3&z=0"></option>
</select>
<input id="searchReset" type="button" />
<input id="searchBtn" type="button" />
</div>
<div id="searchList" class="searchList"><ul id="searchListUl"></ul></div>
</div>
</div>
</div>
<script type="text/javascript" src="image.js"></script>
......
@charset "utf-8";
.wrapper{ width: 570px;_width:575px;margin: 10px auto; zoom:1;position: relative}
.tabbody{height: 335px;}
.tabbody{
height: 335px;
clear: both;
}
.tabhead {
float: left;
}
.tabbody .panel {
position: absolute;
width: 0;
......@@ -797,4 +803,39 @@ i.file-preview.file-type-psd{
background: rgba(0, 0, 0, 0.3);
color: #fff;
padding: 2px 0;
}
/**
* 右侧小导航
*/
.alignBar{
float:right;
position: relative;
}
/**
* 搜索
*/
.none {
display: none;
}
#search-submit {
background: #eee;
font-size: 12px;
color: #666;
height: 25px;
text-align: center;
cursor: pointer;
padding-left: 15px;
padding-right: 15px;
vertical-align: top;
}
#search-input {
padding: 4px 5px;
}
#search-input, #search-submit {
border-radius: 3px;
border: 1px solid #ccc;
outline: none;
}
\ No newline at end of file
......@@ -15,6 +15,12 @@
<span tabSrc="upload" data-content-id="upload"><var id="lang_tab_uploadV"></var></span>
<span tabSrc="online" data-content-id="online"><var id="lang_tab_onlineV"></var></span>
</div>
<div class="alignBar">
<div id="search-container" class="none">
<input type="text" name="keywords" id="search-input" placeholder="其实搜索很简单^_^!" />
<button type="button" class="am-btn am-btn-default am-radius am-btn-xs" id="search-submit">搜索</button>
</div>
</div>
<div id="tabBodys" class="tabbody">
<div id="video" class="panel focus">
<table><tr><td><label for="videoUrl" class="url"><var id="lang_video_url"></var></label></td><td><input id="videoUrl" type="text"></td></tr></table>
......
......@@ -17,6 +17,7 @@
window.onload = function(){
$focus($G("videoUrl"));
initTabs();
initAlign();
initVideo();
initUpload();
};
......@@ -53,13 +54,27 @@
domUtils.removeClasses($G(bodyId), 'focus');
}
}
document.getElementById('search-container').setAttribute('class', 'none');
switch (id) {
case "online":
document.getElementById('search-container').setAttribute('class', '');
initOnline();
break;
}
}
/* 初始化搜索点击事件 */
function initAlign(){
domUtils.on($G("search-submit"), 'click', function(e){
initOnline();
});
}
/* 获取对齐方式 */
function getAlign(){
return 'none';
}
function initVideo(){
createAlignButton( ["videoFloat", "upload_alignment"] );
addUrlChangeListener($G("videoUrl"));
......@@ -202,7 +217,8 @@
'dataType': isJsonp ? 'jsonp':'',
'data': utils.extend({
start: this.listIndex,
size: this.listSize
size: this.listSize,
keywords: document.getElementById('search-input').value
}, editor.queryCommandValue('serverparam')),
'method': 'get',
'onsuccess': function (r) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册