后端模块更新

前端模板路径设置
This commit is contained in:
2020-03-29 21:46:46 +08:00
parent 4893580b70
commit 05654b269c
12 changed files with 123 additions and 49 deletions

View File

@@ -120,4 +120,46 @@ class Base {
View::assign($this->data);
return View::fetch($template);
}
/**
* 是否为手机访问
* @return boolean [description]
*/
public function isMobile() {//return true;
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
// 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
if (isset($_SERVER['HTTP_VIA'])) {
// 找不到为flase,否则为true
return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
}
// 脑残法,判断手机发送的客户端标志,兼容性有待提高
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$clientkeywords = array('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile');
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
return true;
}
}
// 协议法,因为有可能不准确,放到最后判断
if (isset($_SERVER['HTTP_ACCEPT'])) {
// 如果只支持wml并且不支持html那一定是移动设备
// 如果支持wml和html但是wml在html之前则是移动设备
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
return true;
}
}
return false;
}
public function is_wechat() {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
return true;
}
return false;
}
}

View File

@@ -25,7 +25,7 @@ class Channel extends Base {
/* 获取频道列表 */
$map[] = ['status', '>', -1];
if ($type) {
$map['type'] = $type;
$map[] = ['type', '=', $type];
}
$list = $channel->where($map)->order('sort asc,id asc')->select()->append(['status_text'])->toArray();
@@ -157,36 +157,38 @@ class Channel extends Base {
* @author huajie <banhuajie@163.com>
*/
public function sort() {
if ($this->request->isGet()) {
$ids = input('ids');
$pid = input('pid');
//获取排序的数据
$map = array('status' => array('gt', -1));
if (!empty($ids)) {
$map['id'] = array('in', $ids);
} else {
if ($pid !== '') {
$map['pid'] = $pid;
}
}
$list = db('Channel')->where($map)->field('id,title')->order('sort asc,id asc')->select();
$this->assign('list', $list);
$this->setMeta('导航排序');
return $this->fetch();
} elseif ($this->request->isPost()) {
$ids = input('post.ids');
if ($this->request->isPost()) {
$ids = $this->request->param('ids', '');
$ids = explode(',', $ids);
$data = [];
foreach ($ids as $key => $value) {
$res = db('Channel')->where(array('id' => $value))->setField('sort', $key + 1);
$data[] = ['id' => $value, 'sort' => $key];
}
if ($res !== false) {
return $this->success('排序成功!', url('admin/channel/index'));
$result = (new ChannelM())->saveAll($data);
if ($result !== false) {
return $this->success('排序成功!', url('/admin/channel/index'));
} else {
return $this->error('排序失败!');
}
} else {
return $this->error('非法请求!');
}else{
$ids = $this->request->param('ids', '');
$pid = $this->request->param('pid', '');
$map = [];
//获取排序的数据
$map[] = ['status', '>', -1];
if ($ids && strrpos($ids, ",")) {
$map[] = ['id', 'IN', explode(",", $ids)];
}else{
if ($pid) {
$map[] = ['pid', '=', $pid];
}
}
$list = ChannelM::where($map)->field('id,title')->order('sort asc,id asc')->select();
$this->data = [
'list' => $list
];
return $this->fetch();
}
}

View File

@@ -6,10 +6,32 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller;
namespace app\controller\front;
use \app\Base as BaseC;
use think\facade\View;
use think\facade\Cache;
use \app\controller\Base as BaseC;
class Base extends BaseC {
protected function fetch($template = '') {
$config = Cache::get('system_config_data');
$this->tpl_config['view_depr'] = '_';
$pc_themes = $config['pc_themes'] ? $config['pc_themes'] . DIRECTORY_SEPARATOR : "";
$this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $pc_themes;
if ($this->isMobile() && $config['mobile_themes']) {
$mobile_themes = $config['mobile_themes'] ? $config['mobile_themes'] . DIRECTORY_SEPARATOR : "";
$this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $mobile_themes;
if (!is_dir($this->app->getRootPath() . $this->tpl_config['view_dir_name'])) {
$this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $pc_themes;
}
}
if ($template == '') {
$template = str_replace(".", "@", strtolower($this->request->controller())) . "/" . $this->request->action();
}
View::config($this->tpl_config);
View::assign($this->data);
return View::fetch($template);
}
}

View File

@@ -11,7 +11,7 @@ namespace app\controller\front;
use \app\model\Form;
class Front extends Base {
class Index extends Base {
public function index() {
return $this->fetch();