优化知识分享,优化选择部门,岗位选择体验

This commit is contained in:
hdm 2022-11-20 01:10:46 +08:00
parent b4775245d1
commit 6cabfc40d5
8 changed files with 426 additions and 89 deletions

View File

@ -146,6 +146,13 @@ class Index extends BaseController
}
}
//获取部门
public function get_department()
{
$department = get_department();
return to_assign(0, '', $department);
}
//获取部门树形节点列表
public function get_department_tree()
{

View File

@ -22,7 +22,10 @@ class Index extends BaseController
{
if (request()->isAjax()) {
$param = get_params();
$uid = $this->uid;
$did = $this->did;
$where = array();
$whereOr = array();
if (!empty($param['keywords'])) {
$where[] = ['a.id|a.title|a.keywords|a.desc|a.content|c.title', 'like', '%' . $param['keywords'] . '%'];
}
@ -30,9 +33,16 @@ class Index extends BaseController
$where[] = ['a.cate_id', '=', $param['cate_id']];
}
$where[] = ['a.delete_time', '=', 0];
$where[] = ['a.is_share', '=', 1];
$whereOr[] = ['a.is_share', '=', 1];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$did}',a.share_dids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',a.share_uids)")];
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$content = ArticleList::where($where)
->where(function ($query) use($whereOr) {
$query->whereOr($whereOr);
})
->field('a.*,a.id as id,c.title as cate_title,a.title as title,d.title as department,u.name as user')
->alias('a')
->join('article_cate c', 'a.cate_id = c.id')
@ -156,6 +166,20 @@ class Index extends BaseController
View::assign('id', $id);
if ($id > 0) {
$article = (new ArticleList())->detail($id);
if($article['file_ids'] !=''){
$fileArray = Db::name('File')->where('id','in',$article['file_ids'])->select();
$article['fileArray'] = $fileArray;
}
$article['share_depaments'] = '';
if($article['share_dids'] !=''){
$depamentArray = Db::name('Department')->where('id','in',$article['share_dids'])->column('title');
$article['share_depaments'] = implode(',',$depamentArray);
}
$article['share_names'] = '';
if($article['share_uids'] !=''){
$uidArray = Db::name('Admin')->where('id','in',$article['share_uids'])->column('name');
$article['share_names'] = implode(',',$uidArray);
}
View::assign('article', $article);
return view('edit');
}
@ -167,8 +191,25 @@ class Index extends BaseController
public function view()
{
$id = get_params("id");
$uid=$this->uid;
$did=$this->did;
$detail = (new ArticleList())->detail($id);
$share_uids = [];
if(!empty($detail['share_uids'])){
$share_uids = explode(',', $detail['share_uids']);
}
$share_dids = [];
if(!empty($detail['share_dids'])){
$share_uids = explode(',', $detail['share_dids']);
}
if($detail['uid'] !=$uid && !in_array($uid,$share_uids) && !in_array($did,$share_dids) && $detail['is_share'] !=1){
throw new \think\exception\HttpException(405, '无权限访问');
}
$detail['cate_title'] = Db::name('ArticleCate')->where(['id' => $detail['cate_id']])->value('title');
if($detail['file_ids'] !=''){
$fileArray = Db::name('File')->where('id','in',$detail['file_ids'])->select();
$detail['fileArray'] = $fileArray;
}
// read 字段加 1
Db::name('article')->where('id', $id)->inc('read')->update();
View::assign('detail', $detail);

View File

@ -4,53 +4,82 @@
<form class="layui-form p-4">
<h3 class="pb-3">新增知识文章</h3>
<table class="layui-table">
<tr>
<td class="layui-td-gray">文章标题<font>*</font></td>
<td colspan="3"><input type="text" name="title" lay-verify="required" lay-reqText="请输入文章标题" autocomplete="off" placeholder="请输入文章标题"
class="layui-input"></td>
<td class="layui-td-gray">文章分类<font>*</font></td>
<td>
<select name="cate_id" lay-verify="required" lay-reqText="请选择分类">
<option value="">请选择分类</option>
{volist name=":set_recursion(article_cate())" id="v"}
<option value="{$v.id}">{$v.title}</option>
{/volist}
</select>
</td>
</tr>
<tr>
<td class="layui-td-gray">关键字<font>*</font></td>
<td colspan="3">
<input type="text" id="keyword_name" name="keyword_names" autocomplete="off" lay-verify="required" lay-reqText="请选择关键字" placeholder="请选择关键字"
class="layui-input" readonly>
<input type="hidden" id="keyword_id" name="keyword_ids" autocomplete="off">
</td>
<td class="layui-td-gray">属性</td>
<td>
<select name="type">
<option value="">请选择属性</option>
<option value="1">精华</option>
<option value="2">热门</option>
<option value="3">推荐</option>
</select>
</td>
</tr>
<tr>
<td class="layui-td-gray">是否共享</td>
<td>
<input type="radio" name="is_share" value="1" title="是" checked>
<input type="radio" name="is_share" value="0" title="否">
</td>
<td class="layui-td-gray" style="width:50px">状态</td>
<td>
<input type="radio" name="status" value="1" title="正常" checked>
<input type="radio" name="status" value="0" title="下架">
</td>
<td class="layui-td-gray">排序</td>
<td>
<input type="text" name="sort" value="0" placeholder="请输入排序,数字" autocomplete="off" class="layui-input">
</td>
</tr>
<tr>
<td class="layui-td-gray">文章标题<font>*</font></td>
<td colspan="3"><input type="text" name="title" lay-verify="required" lay-reqText="请输入文章标题" autocomplete="off" placeholder="请输入文章标题"
class="layui-input"></td>
<td class="layui-td-gray">文章分类<font>*</font></td>
<td>
<select name="cate_id" lay-verify="required" lay-reqText="请选择分类">
<option value="">请选择分类</option>
{volist name=":set_recursion(article_cate())" id="v"}
<option value="{$v.id}">{$v.title}</option>
{/volist}
</select>
</td>
</tr>
<tr>
<td class="layui-td-gray">关键字<font>*</font></td>
<td colspan="3">
<input type="text" id="keyword_name" name="keyword_names" autocomplete="off" lay-verify="required" lay-reqText="请选择关键字" placeholder="请选择关键字"
class="layui-input" readonly>
<input type="hidden" id="keyword_id" name="keyword_ids" autocomplete="off">
</td>
<td class="layui-td-gray">属性</td>
<td>
<select name="type">
<option value="">请选择属性</option>
<option value="1">精华</option>
<option value="2">热门</option>
<option value="3">推荐</option>
</select>
</td>
</tr>
<tr>
<td class="layui-td-gray">共享设置</td>
<td>
<input type="radio" name="is_share" lay-filter="type" value="0" title="私有">
<input type="radio" name="is_share" lay-filter="type" value="1" title="所有人" checked>
<input type="radio" name="is_share" lay-filter="type" value="2" title="部门">
<input type="radio" name="is_share" lay-filter="type" value="3" title="部分人员">
</td>
<td class="layui-td-gray" style="width:50px">状态</td>
<td>
<input type="radio" name="status" value="1" title="正常" checked>
<input type="radio" name="status" value="0" title="下架">
</td>
<td class="layui-td-gray">排序</td>
<td>
<input type="text" name="sort" value="0" placeholder="请输入排序,数字" autocomplete="off" class="layui-input">
</td>
</tr>
<tr id="depament" style="display:none">
<td class="layui-td-gray">共享部门<font>*</font></td>
<td colspan="5">
<input type="text" name="share_depaments" value="" placeholder="请选择共享部门" readonly class="layui-input picker-depaments">
<input type="hidden" name="share_dids" value="">
</td>
</tr>
<tr id="person" style="display:none">
<td class="layui-td-gray">共享人员<font>*</font></td>
<td colspan="5">
<input type="text" name="share_names" value="" placeholder="请选择共享人员" readonly class="layui-input picker-more">
<input type="hidden" name="share_uids" value="">
</td>
</tr>
<tr>
<td class="layui-td-gray-2">
<div class="layui-input-inline">关联附件</div>
<div class="layui-input-inline">
<button type="button" class="layui-btn layui-btn-xs" id="uploadBtn"><i class="layui-icon"></i></button>
</div>
</td>
<td colspan="5" style="line-height:inherit">
<div class="layui-row" id="fileBox">
<input type="hidden" id="fileBoxInput" name="file_ids" value="">
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="vertical-align:top;">文章摘要</td>
<td colspan="3">
@ -85,16 +114,38 @@
<!-- 脚本 -->
{block name="script"}
<script>
const moduleInit = ['tool','tagpicker','tinymce'];
function gouguInit() {
var form = layui.form,tool=layui.tool, tagspicker = layui.tagpicker, upload = layui.upload;
const moduleInit = ['tool','employeepicker','oaTool','tagpicker','tinymce'];
function gouguInit() {
var form = layui.form,tool=layui.tool,oaTool = layui.oaTool, tagspicker = layui.tagpicker, upload = layui.upload;
//选择共享类型
form.on('radio(type)', function (data) {
if(data.value==2){
$('#person').hide();
$('#depament').show();
}
else if(data.value==3){
$('#person').show();
$('#depament').hide();
}
else{
$('#person').hide();
$('#depament').hide();
}
});
//编辑器初始化
var editor = layui.tinymce;
var edit = editor.render({
selector: "#container",
images_upload_url: '/api/index/upload/sourse/tinymce',//图片上传接口
height: 500
});
var editor = layui.tinymce;
var edit = editor.render({
selector: "#container",
images_upload_url: '/api/index/upload/sourse/tinymce',//图片上传接口
height: 500
});
//相关附件上传
oaTool.addFile();
//tag选择
var tags = new tagspicker({
'url': "/api/index/get_keyword_cate",
'target': 'keyword_name',
@ -121,14 +172,32 @@
//监听提交
form.on('submit(webform)', function (data) {
data.field.content = tinyMCE.editors['container'].getContent();
if (data.field.content == '') {
layer.msg('请先完善文章只是内容');
if (data.field.content == '') {
layer.msg('请先完善文章的内容');
return false;
}
if(data.field.is_share == 0 || data.field.is_share == 1){
data.field.share_dids = '';
data.field.share_uids = '';
}
else if(data.field.is_share == 2){
data.field.share_uids = '';
if(data.field.share_dids==''){
layer.msg('请先选择共享的部门');
return false;
}
}
else if(data.field.is_share == 3){
data.field.share_dids = '';
if(data.field.share_uids==''){
layer.msg('请先选择共享的员工');
return false;
}
}
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
parent.layui.tool.close(1000);
tool.sideClose(1000);
}
}
tool.post("/article/index/add", data.field, callback);

View File

@ -38,8 +38,10 @@
<tr>
<td class="layui-td-gray">是否共享<font>*</font></td>
<td>
<input type="radio" name="is_share" value="1" title="是" {eq name="$article.is_share" value="1" }checked{/eq}>
<input type="radio" name="is_share" value="0" title="否" {eq name="$article.is_share" value="0" }checked{/eq}>
<input type="radio" name="is_share" lay-filter="type" value="0" title="私有" {eq name="$article.is_share" value="0" }checked{/eq}>
<input type="radio" name="is_share" lay-filter="type" value="1" title="所有人" {eq name="$article.is_share" value="1" }checked{/eq}>
<input type="radio" name="is_share" lay-filter="type" value="2" title="部门" {eq name="$article.is_share" value="2" }checked{/eq}>
<input type="radio" name="is_share" lay-filter="type" value="3" title="部分人员" {eq name="$article.is_share" value="3" }checked{/eq}>
</td>
<td class="layui-td-gray" style="width:50px">状态</td>
<td>
@ -51,6 +53,47 @@
<input type="text" name="sort" placeholder="请输入排序,数字" autocomplete="off" class="layui-input" value="{$article.sort}">
</td>
</tr>
<tr id="depament" style="{$article.is_share == 2?'':'display:none'}">
<td class="layui-td-gray">共享部门<font>*</font></td>
<td colspan="5">
<input type="text" name="share_depaments" value="{$article.share_depaments}" placeholder="请选择共享部门" readonly class="layui-input picker-depaments">
<input type="hidden" name="share_dids" value="{$article.share_dids}">
</td>
</tr>
<tr id="person" style="{$article.is_share == 3?'':'display:none'}">
<td class="layui-td-gray">共享人员<font>*</font></td>
<td colspan="5">
<input type="text" name="share_names" value="{$article.share_names}" placeholder="请选择共享人员" readonly class="layui-input picker-more">
<input type="hidden" name="share_uids" value="{$article.share_uids}">
</td>
</tr>
<tr>
<td class="layui-td-gray-2">
<div class="layui-input-inline">关联附件</div>
<div class="layui-input-inline">
<button type="button" class="layui-btn layui-btn-xs" id="uploadBtn"><i class="layui-icon"></i></button>
</div>
</td>
<td colspan="5" style="line-height:inherit">
<div class="layui-row" id="fileBox">
<input type="hidden" id="fileBoxInput" name="file_ids" value="{$article.file_ids}">
{notempty name="$article.file_ids"}
{volist name="$article.fileArray" id="vo"}
<div class="layui-col-md4" id="fileItem{$vo.id}">
<div class="file-card">
<i class="file-icon iconfont icon-renwuguanli"></i>
<div class="file-title">{$vo.name}</div>
<div class="file-tool">
<a href="{$vo.filepath}" download="{$vo.name}" target="_blank" title="下载查看"><i class="iconfont icon-shujudaoru blue"></i></a>
<i class="btn-delete iconfont icon-shanchu red" data-id="{$vo.id}" title="删除"></i>
</div>
</div>
</div>
{/volist}
{/notempty}
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="vertical-align:top;">文章摘要</td>
<td colspan="3">
@ -87,17 +130,38 @@
<!-- 脚本 -->
{block name="script"}
<script>
const moduleInit = ['tool','tagpicker','tinymce'];
function gouguInit() {
var form = layui.form,tool=layui.tool, tagspicker = layui.tagpicker, upload = layui.upload;
const moduleInit = ['tool','employeepicker','oaTool','tagpicker','tinymce'];
function gouguInit() {
var form = layui.form,tool=layui.tool,oaTool = layui.oaTool, tagspicker = layui.tagpicker, upload = layui.upload;
//选择共享类型
form.on('radio(type)', function (data) {
if(data.value==2){
$('#person').hide();
$('#depament').show();
}
else if(data.value==3){
$('#person').show();
$('#depament').hide();
}
else{
$('#person').hide();
$('#depament').hide();
}
});
//编辑器初始化
var editor = layui.tinymce;
var edit = editor.render({
selector: "#container",
images_upload_url: '/api/index/upload/sourse/tinymce',//图片上传接口
height: 500
});
var editor = layui.tinymce;
var edit = editor.render({
selector: "#container",
images_upload_url: '/api/index/upload/sourse/tinymce',//图片上传接口
height: 500
});
//相关附件上传
oaTool.addFile();
//tag选择
var tags = new tagspicker({
'url': "/api/index/get_keyword_cate",
'target': 'keyword_name',
@ -109,29 +173,49 @@ const moduleInit = ['tool','tagpicker','tinymce'];
//封面上传
var uploadInst = upload.render({
elem: '#test1',
url: "/api/index/upload",
done: function (res) {
layer.msg(res.msg);
if (res.code == 0) {
//上传成功
$('#demo1 input').attr('value', res.data.id);
$('#demo1 img').attr('src', res.data.filepath);
}
elem: '#test1',
url: "/api/index/upload",
done: function (res) {
layer.msg(res.msg);
if (res.code == 0) {
//上传成功
$('#demo1 input').attr('value', res.data.id);
$('#demo1 img').attr('src', res.data.filepath);
}
}
});
//监听提交
form.on('submit(webform)', function (data) {
data.field.content = tinyMCE.editors['container'].getContent();
if (data.field.content == '') {
layer.msg('请先完善文章只是内容');
data.field.content = tinyMCE.editors['container'].getContent();
if (data.field.content == '') {
layer.msg('请先完善文章的内容');
return false;
}
if(data.field.is_share == 0 || data.field.is_share == 1){
data.field.share_dids = '';
data.field.share_uids = '';
}
else if(data.field.is_share == 2){
data.field.share_uids = '';
if(data.field.share_dids==''){
layer.msg('请先选择共享的部门');
return false;
}
let callback = function (e) {
}
else if(data.field.is_share == 3){
data.field.share_dids = '';
if(data.field.share_uids==''){
layer.msg('请先选择共享的员工');
return false;
}
}
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
parent.layui.tool.close(1000);
tool.sideClose(1000);
}
}
tool.post("/article/index/add", data.field, callback);

View File

@ -23,7 +23,7 @@
<i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
</script>
<script type="text/html" id="is_share">
<i class="layui-icon {{# if(d.is_share == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
<i class="layui-icon {{# if(d.is_share == 0){ }}layui-icon-close{{# } else { }}layui-icon-ok{{# } }}"></i>
</script>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">

View File

@ -43,6 +43,22 @@
<div class="text-detial-content">
{$detail.content|raw}
</div>
{notempty name="$detail.file_ids"}
<h3 class="py-3">相关附件</h3>
<div class="layui-row" id="fileBox">
{volist name="$detail.fileArray" id="vo"}
<div class="layui-col-md4" id="fileItem{$vo.id}">
<div class="file-card">
<i class="file-icon iconfont icon-renwuguanli"></i>
<div class="file-title file-title-view">{$vo.name}</div>
<div class="file-tool">
<a href="{$vo.filepath}" download="{$vo.name}" target="_blank" title="下载查看"><i class="iconfont icon-shujudaoru blue"></i></a>
</div>
</div>
</div>
{/volist}
</div>
{/notempty}
</div>
{/block}
<!-- /主体 -->

View File

@ -1869,10 +1869,13 @@ CREATE TABLE `oa_article` (
`uid` int(11) NOT NULL DEFAULT 0 COMMENT '作者',
`did` int(11) NOT NULL DEFAULT 0 COMMENT '部门',
`origin_url` varchar(255) NOT NULL DEFAULT '' COMMENT '来源地址',
`file_ids` varchar(500) NOT NULL DEFAULT '' COMMENT '相关附件',
`share_dids` varchar(500) NOT NULL DEFAULT '' COMMENT '分享部门',
`share_dids` varchar(500) NOT NULL DEFAULT '' COMMENT '分享用户',
`content` text NOT NULL COMMENT '文章内容',
`read` int(11) NOT NULL DEFAULT 0 COMMENT '阅读量',
`type` tinyint(2) NOT NULL DEFAULT 0 COMMENT '属性1精华 2热门 3推荐',
`is_share` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否分享0否1是',
`is_share` tinyint(1) NOT NULL DEFAULT 1 COMMENT '分享0私有,1所有人,2部门,3人员',
`status` int(1) NOT NULL DEFAULT 1 COMMENT '状态:1正常-1下架',
`sort` int(11) NOT NULL DEFAULT 0 COMMENT '排序',
`create_time` int(11) NOT NULL DEFAULT 0,

View File

@ -125,6 +125,79 @@ layui.define(['tool'], function (exports) {
}
});
},
//选择部门
departmentPicker:function(type,callback){
let select_type = type==1?'radio':'checkbox',departmentTable;
layer.open({
type:1,
title:'选择部门',
area:['500px','536px'],
content:`<div style="width:468px; height:420px; padding:12px;">
<div id="departmentBox"></div>
</div>`,
success:function(){
departmentTable=table.render({
elem: '#departmentBox'
,url: "/api/index/get_department"
,page: false //开启分页
,cols: [[
{type:select_type,title: '选择'}
,{field:'id', width:80, title: '编号', align:'center'}
,{field:'title',title: '部门名称'}
]]
});
},
btn: ['确定'],
btnAlign:'c',
yes: function(){
var checkStatus = table.checkStatus(departmentTable.config.id);
var data = checkStatus.data;
if(data.length>0){
callback(data);
layer.closeAll();
}else{
layer.msg('请选择部门');
return;
}
}
})
},
//选择岗位
positionPicker:function(type,callback){
let select_type = type==1?'radio':'checkbox',positionTable;
layer.open({
title:'选择岗位',
type:1,
area:['390px','436px'],
content:'<div style="padding:12px"><div id="positionBox"></div></div>',
success:function(){
positionTable=table.render({
elem: '#positionBox'
,url: "/api/index/get_position"
,page: false //开启分页
,cols: [[
{type:select_type,title: '选择'}
,{field:'id', width:80, title: '编号', align:'center'}
,{field:'name',title: '岗位名称'}
]]
});
},
btn: ['确定'],
btnAlign:'c',
yes: function(){
var checkStatus = table.checkStatus(positionTable.config.id);
var data = checkStatus.data;
if(data.length>0){
callback(data);
layer.closeAll();
}else{
layer.msg('请选择岗位');
return;
}
}
})
},
//选择客户
customerPicker:function(callback){
var customeTable;
layer.open({
@ -173,6 +246,7 @@ layui.define(['tool'], function (exports) {
}
})
},
//选择合同
contractPicker:function(callback){
var contractTable;
layer.open({
@ -182,7 +256,7 @@ layui.define(['tool'], function (exports) {
content: '<div class="picker-table">\
<form class="layui-form pb-2">\
<div class="layui-input-inline" style="width:480px;">\
<input type="text" name="keywords" placeholder="合同名称" class="layui-input" autocomplete="off" />\
<input type="text" name="keywords" placeholder="合同名称" class="layui-input" autocomplete="off" />\
</div>\
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="search_contract">提交搜索</button>\
</form>\
@ -223,13 +297,56 @@ layui.define(['tool'], function (exports) {
}
};
//选择部门
$('body').on('click','.picker-depament',function () {
let that = $(this);
let callback = function(data){
that.val(data[0].title);
that.next().val(data[0].id);
}
obj.departmentPicker(1,callback);
});
$('body').on('click','.picker-depaments',function () {
let that = $(this),ids = [],names=[];
let callback = function(data){
for ( var i = 0; i <data.length; i++){
ids.push(data[i].id);
names.push(data[i].title);
}
that.val(names.join(','));
that.next().val(ids.join(','));
}
obj.departmentPicker(2,callback);
});
//选择岗位
$('body').on('click','.picker-position',function () {
let that = $(this);
let callback = function(data){
that.val(data[0].name);
that.next().val(data[0].id);
}
obj.positionPicker(1,callback);
});
$('body').on('click','.picker-positions',function () {
let that = $(this),ids = [],names=[];
let callback = function(data){
for ( var i = 0; i <data.length; i++){
ids.push(data[i].id);
names.push(data[i].name);
}
that.val(names.join(','));
that.next().val(ids.join(','));
}
obj.positionPicker(2,callback);
});
//选择客户
$('body').on('click','.picker-customer',function () {
let that = $(this);
let callback = function(data){
that.val(data.name);
that.next.val(data.id);
that.next().val(data.id);
}
obj.customerPicker(callback);
});