营养小知识修改优化
This commit is contained in:
parent
f2d2e8c8ac
commit
d697ba73ee
@ -1,7 +1,10 @@
|
||||
package com.stdiet.web.controller;
|
||||
|
||||
import com.stdiet.common.config.AliyunOSSConfig;
|
||||
import com.stdiet.common.core.domain.entity.SysUser;
|
||||
import com.stdiet.common.utils.StringUtils;
|
||||
import com.stdiet.common.utils.oss.AliyunOSSUtils;
|
||||
import com.stdiet.common.utils.poi.ExcelUtil;
|
||||
import com.stdiet.custom.domain.SysNutritionQuestion;
|
||||
import com.stdiet.custom.domain.SysWxUserInfo;
|
||||
import com.stdiet.custom.domain.SysWxUserLog;
|
||||
@ -23,6 +26,7 @@ import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@ -38,19 +42,13 @@ public class MyApplicationRunner implements ApplicationRunner {
|
||||
@Autowired
|
||||
private ISysNutritionQuestionService sysNutritionQuestionService;
|
||||
|
||||
@Autowired
|
||||
private ISysWxUserLogService sysWxUserLogService;
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
System.out.println("项目启动调用方法");
|
||||
|
||||
/*SysNutritionQuestion sysNutritionQuestion = new SysNutritionQuestion();
|
||||
sysNutritionQuestion.setTitle("如何防止猝死");
|
||||
sysNutritionQuestion.setContent("少熬夜,少暴饮暴食");
|
||||
sysNutritionQuestion.setKey("猝死");
|
||||
sysNutritionQuestionService.insertSysNutritionQuestion(sysNutritionQuestion);*/
|
||||
System.out.println("--------------项目启动调用方法开始----------");
|
||||
|
||||
System.out.println("--------------项目启动调用方法结束-------------");
|
||||
}
|
||||
|
||||
|
||||
@ -75,4 +73,36 @@ public class MyApplicationRunner implements ApplicationRunner {
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入营养小知识方法
|
||||
* @param path
|
||||
*/
|
||||
public void importNutritionQuestion(String path){
|
||||
try{
|
||||
int count = 0;
|
||||
ExcelUtil<SysNutritionQuestion> util = new ExcelUtil<SysNutritionQuestion>(SysNutritionQuestion.class);
|
||||
File file = new File(path);
|
||||
List<SysNutritionQuestion> questionList = util.importExcel(new FileInputStream(file));
|
||||
System.out.println(questionList.size());
|
||||
for (SysNutritionQuestion sysNutritionQuestion : questionList) {
|
||||
//System.out.println(sysNutritionQuestion);
|
||||
if(StringUtils.isNotEmpty(sysNutritionQuestion.getTitle())
|
||||
&& StringUtils.isNotEmpty(sysNutritionQuestion.getContent())){
|
||||
//System.out.println(sysNutritionQuestion.getTitle() + "\n");
|
||||
sysNutritionQuestion.setShowFlag(1);
|
||||
if(sysNutritionQuestionService.insertSysNutritionQuestion(sysNutritionQuestion) > 0){
|
||||
count++;
|
||||
Thread.sleep(100);
|
||||
System.out.println(count);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
System.out.println("结束:"+count);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.stdiet.custom.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.stdiet.common.utils.StringUtils;
|
||||
import com.stdiet.custom.domain.SysCustomerCase;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.aspectj.weaver.loadtime.Aj;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -104,4 +107,19 @@ public class SysNutritionQuestionController extends BaseController
|
||||
{
|
||||
return toAjax(sysNutritionQuestionService.regenerateNutritionQuestionIndex() ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改营养小知识是否微信展示状态
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('custom:nutritionQuestion:edit')")
|
||||
@Log(title = "微信展示状态修改", businessType = BusinessType.UPDATE)
|
||||
@GetMapping("/updateWxShow")
|
||||
public AjaxResult updateWxShow(@RequestParam("id")String id, @RequestParam("showFlag")Integer showFlag)
|
||||
{
|
||||
if(StringUtils.isEmpty(id) || showFlag == null){
|
||||
return AjaxResult.error();
|
||||
}
|
||||
Long[] ids = {Long.parseLong(id)};
|
||||
return toAjax(sysNutritionQuestionService.updateWxShowByIds(showFlag, ids));
|
||||
}
|
||||
}
|
@ -285,10 +285,11 @@ public class WechatAppletController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信用户记录详细信息
|
||||
* 获取小程序展示的营养小知识列表
|
||||
*/
|
||||
@GetMapping(value = "/getNutritionQuestionList")
|
||||
public AjaxResult getNutritionQuestionList(SysNutritionQuestion sysNutritionQuestion, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10")int pageSize) {
|
||||
sysNutritionQuestion.setShowFlag(1);
|
||||
Map<String,Object> result = sysNutritionQuestionService.getNutritionQuestionListByKey(sysNutritionQuestion, pageNum, pageSize);
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ public class SysNutritionQuestion extends BaseEntity
|
||||
/** $column.columnComment */
|
||||
private Long id;
|
||||
|
||||
private Long[] ids;
|
||||
|
||||
/** 标题 */
|
||||
@Excel(name = "标题")
|
||||
private String title;
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.stdiet.custom.dto.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.stdiet.common.annotation.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class NutritionQuestionResponse implements Serializable {
|
||||
@ -14,14 +16,14 @@ public class NutritionQuestionResponse implements Serializable {
|
||||
private String id;
|
||||
|
||||
/** 标题 */
|
||||
@Excel(name = "标题")
|
||||
private String title;
|
||||
|
||||
/** 内容 */
|
||||
@Excel(name = "内容")
|
||||
private String content;
|
||||
|
||||
/** 关键词,逗号隔开 */
|
||||
@Excel(name = "关键词,逗号隔开")
|
||||
private String key;
|
||||
|
||||
/** 小程序是否显示,0不显示 1显示 */
|
||||
private String showFlag;
|
||||
}
|
||||
|
@ -79,4 +79,12 @@ public interface SysNutritionQuestionMapper
|
||||
* @return
|
||||
*/
|
||||
public List<SysNutritionQuestion> getNutritionQuestionListByPage(@Param("start")int start, @Param("pageSize")int pageSize);
|
||||
|
||||
/**
|
||||
* 更新微信展示状态
|
||||
* @param wxShow 是否展示 0不展示 1展示
|
||||
* @param ids id数组
|
||||
* @return
|
||||
*/
|
||||
public int updateWxShowByIds(@Param("wxShow")Integer wxShow, @Param("array") Long[] ids);
|
||||
}
|
@ -73,4 +73,12 @@ public interface ISysNutritionQuestionService
|
||||
*/
|
||||
public boolean regenerateNutritionQuestionIndex();
|
||||
|
||||
/**
|
||||
* 更新微信展示状态
|
||||
* @param wxShow 是否展示 0不展示 1展示
|
||||
* @param ids id数组
|
||||
* @return
|
||||
*/
|
||||
public int updateWxShowByIds(Integer wxShow, Long[] ids);
|
||||
|
||||
}
|
@ -6,12 +6,17 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.stdiet.common.utils.DateUtils;
|
||||
import com.stdiet.common.utils.StringUtils;
|
||||
import com.stdiet.common.utils.reflect.ReflectUtils;
|
||||
import com.stdiet.custom.dto.response.NutritionQuestionResponse;
|
||||
import com.stdiet.custom.utils.LuceneIndexUtils;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.util.Version;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -35,10 +40,19 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer
|
||||
public String index_path;
|
||||
|
||||
//建立索引的字段名称
|
||||
public static final String[] index_field_array = {"id", "title", "content", "key"};
|
||||
public static final String[] index_field_array = {"id", "title", "content", "key", "showFlag"};
|
||||
//查询字段
|
||||
public static final String[] index_select_field_array = {"title", "content", "key"};
|
||||
|
||||
public static Map<String, Integer> nutritionQuestionBoostMap = null;
|
||||
|
||||
static{
|
||||
nutritionQuestionBoostMap = new HashMap<>();
|
||||
nutritionQuestionBoostMap.put("key", 100);
|
||||
nutritionQuestionBoostMap.put("title", 80);
|
||||
nutritionQuestionBoostMap.put("content", 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询营养知识小问答
|
||||
*
|
||||
@ -74,7 +88,7 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer
|
||||
{
|
||||
sysNutritionQuestion.setCreateTime(DateUtils.getNowDate());
|
||||
if(sysNutritionQuestionMapper.insertSysNutritionQuestion(sysNutritionQuestion) > 0){
|
||||
return createNutritionQuestionIndex(sysNutritionQuestion) ? 1 : 0;
|
||||
return createNutritionQuestionIndex(sysNutritionQuestion.getId()) ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -90,7 +104,7 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer
|
||||
{
|
||||
sysNutritionQuestion.setUpdateTime(DateUtils.getNowDate());
|
||||
if(sysNutritionQuestionMapper.updateSysNutritionQuestion(sysNutritionQuestion) > 0){
|
||||
return updateNutritionQuestionIndex(sysNutritionQuestion) ? 1 : 0;
|
||||
return updateNutritionQuestionIndex(sysNutritionQuestion.getId()) ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -152,7 +166,24 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer
|
||||
try{
|
||||
//建立索引
|
||||
LuceneIndexUtils luceneIndexUtils = LuceneIndexUtils.getLuceneIndexUtils(index_path);
|
||||
Map<String, Object> indexMap = luceneIndexUtils.queryByKeyword(sysNutritionQuestion.getKey(), index_select_field_array, pageNum, pageSize);
|
||||
|
||||
//建立查询语句
|
||||
BooleanQuery booleanQuery = new BooleanQuery();
|
||||
|
||||
//装配
|
||||
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_44, index_select_field_array, luceneIndexUtils.analyzer);
|
||||
|
||||
//解析输入关键字
|
||||
Query keywordQuery = StringUtils.isEmpty(sysNutritionQuestion.getKey()) ? new WildcardQuery(new Term(LuceneIndexUtils.default_primary_key, "*")) : queryParser.parse(sysNutritionQuestion.getKey());
|
||||
|
||||
booleanQuery.add(keywordQuery, BooleanClause.Occur.MUST);
|
||||
|
||||
if(sysNutritionQuestion.getShowFlag() != null){
|
||||
Query showFlagQuery = new TermQuery(new Term("showFlag", sysNutritionQuestion.getShowFlag().intValue()+""));
|
||||
booleanQuery.add(showFlagQuery, BooleanClause.Occur.MUST);
|
||||
}
|
||||
|
||||
Map<String, Object> indexMap = luceneIndexUtils.queryByKeyword(booleanQuery, StringUtils.isNotEmpty(sysNutritionQuestion.getKey()), pageNum, pageSize);
|
||||
total = (int)indexMap.get("total");
|
||||
List<Document> documentList = (List<Document>)indexMap.get("data");
|
||||
if(documentList != null && documentList.size() > 0){
|
||||
@ -204,7 +235,8 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer
|
||||
* @param sysNutritionQuestion
|
||||
* @return
|
||||
*/
|
||||
private boolean createNutritionQuestionIndex(SysNutritionQuestion sysNutritionQuestion){
|
||||
private boolean createNutritionQuestionIndex(Long id){
|
||||
SysNutritionQuestion sysNutritionQuestion = selectSysNutritionQuestionById(id);
|
||||
try{
|
||||
//建立索引
|
||||
LuceneIndexUtils luceneIndexUtils = LuceneIndexUtils.getLuceneIndexUtils(index_path);
|
||||
@ -221,8 +253,9 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer
|
||||
* @param sysNutritionQuestion
|
||||
* @return
|
||||
*/
|
||||
private boolean updateNutritionQuestionIndex(SysNutritionQuestion sysNutritionQuestion){
|
||||
private boolean updateNutritionQuestionIndex(Long id){
|
||||
try{
|
||||
SysNutritionQuestion sysNutritionQuestion = selectSysNutritionQuestionById(id);
|
||||
//建立索引
|
||||
LuceneIndexUtils luceneIndexUtils = LuceneIndexUtils.getLuceneIndexUtils(index_path);
|
||||
Document document = nutritionQuestionToDocument(sysNutritionQuestion);
|
||||
@ -247,10 +280,19 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer
|
||||
return nutritionQuestionResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sysNutritionQuestion
|
||||
* @return
|
||||
*/
|
||||
private Document nutritionQuestionToDocument(SysNutritionQuestion sysNutritionQuestion){
|
||||
Document document = new Document();
|
||||
for (String fieldName : index_field_array) {
|
||||
document.add(new TextField(fieldName, ReflectUtils.getFieldValue(sysNutritionQuestion, fieldName)+"", Field.Store.YES));
|
||||
TextField field = new TextField(fieldName, ReflectUtils.getFieldValue(sysNutritionQuestion, fieldName)+"", Field.Store.YES);
|
||||
if(nutritionQuestionBoostMap.containsKey(fieldName)){
|
||||
field.setBoost(nutritionQuestionBoostMap.get(fieldName).floatValue());
|
||||
}
|
||||
document.add(field);
|
||||
}
|
||||
return document;
|
||||
}
|
||||
@ -258,12 +300,24 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer
|
||||
private List<Document> nutritionQuestionToDocument(List<SysNutritionQuestion> sysNutritionQuestionList){
|
||||
List<Document> result = new ArrayList<>();
|
||||
for (SysNutritionQuestion sysNutritionQuestion : sysNutritionQuestionList) {
|
||||
Document document = new Document();
|
||||
for (String fieldName : index_field_array) {
|
||||
document.add(new TextField(fieldName, ReflectUtils.getFieldValue(sysNutritionQuestion, fieldName)+"", Field.Store.YES));
|
||||
}
|
||||
result.add(document);
|
||||
result.add(nutritionQuestionToDocument(sysNutritionQuestion));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新微信展示状态
|
||||
* @param wxShow 是否展示 0不展示 1展示
|
||||
* @param ids id数组
|
||||
* @return
|
||||
*/
|
||||
public int updateWxShowByIds(Integer wxShow, Long[] ids){
|
||||
if(sysNutritionQuestionMapper.updateWxShowByIds(wxShow, ids) > 0){
|
||||
for (Long id : ids) {
|
||||
updateNutritionQuestionIndex(id);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -26,29 +26,39 @@ import java.util.Map;
|
||||
public class LuceneIndexUtils {
|
||||
|
||||
//分词器
|
||||
private IKAnalyzer analyzer = null;
|
||||
public static IKAnalyzer analyzer = null;
|
||||
//分词器工具
|
||||
private static IndexWriterConfig config = null;
|
||||
//索引库
|
||||
private Directory directory = null;
|
||||
//分词器工具
|
||||
private IndexWriterConfig config = null;
|
||||
//流
|
||||
private IndexWriter indexWriter= null;
|
||||
//获得读取对象
|
||||
private IndexSearcher indexSearcher = null;
|
||||
|
||||
public static final String default_primary_key = "id";
|
||||
|
||||
public static final Integer max_select_count = 1000;
|
||||
public static final Integer max_select_count = 10000;
|
||||
|
||||
static{
|
||||
//分词器
|
||||
analyzer = new IKAnalyzer();
|
||||
//使用智能分词
|
||||
analyzer.setUseSmart(true);
|
||||
//工具装配分词器
|
||||
config = new IndexWriterConfig(Version.LUCENE_44, analyzer);
|
||||
|
||||
}
|
||||
|
||||
public static LuceneIndexUtils getLuceneIndexUtils(String indexPath){
|
||||
LuceneIndexUtils luceneIndexUtils = new LuceneIndexUtils();
|
||||
try {
|
||||
//分词器
|
||||
luceneIndexUtils.analyzer = new IKAnalyzer();
|
||||
//使用智能分词
|
||||
luceneIndexUtils.analyzer.setUseSmart(true);
|
||||
//索引库
|
||||
luceneIndexUtils.directory = FSDirectory.open(new File(indexPath));
|
||||
//工具装配分词器
|
||||
luceneIndexUtils.config = new IndexWriterConfig(Version.LUCENE_44, luceneIndexUtils.analyzer);
|
||||
//读索引库流
|
||||
IndexReader reader = DirectoryReader.open(luceneIndexUtils.directory);
|
||||
//获得读取对象
|
||||
luceneIndexUtils.indexSearcher = new IndexSearcher(reader);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -220,34 +230,21 @@ public class LuceneIndexUtils {
|
||||
|
||||
/**
|
||||
* 查询索引库的数据(根据输入关键字)
|
||||
* @param keyword
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Map<String, Object> queryByKeyword(String keyword, String[] columns, int pageNum, int pageSize) throws Exception {
|
||||
public Map<String, Object> queryByKeyword(BooleanQuery query, Boolean boostSort, int pageNum, int pageSize) throws Exception {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
//指定读取索引库的列数据
|
||||
//String[] columns = {"articleId","articleName","articleImage","articleContent"};
|
||||
|
||||
//装配
|
||||
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_44, columns, analyzer);
|
||||
|
||||
//解析输入关键字
|
||||
Query query = StringUtils.isEmpty(keyword) ? new WildcardQuery(new Term(default_primary_key, "*")) : queryParser.parse(keyword);
|
||||
|
||||
//读索引库流
|
||||
IndexReader reader = DirectoryReader.open(directory);
|
||||
|
||||
//获得读取对象
|
||||
IndexSearcher indexSearcher = new IndexSearcher(reader);
|
||||
|
||||
//排序
|
||||
Sort sort = null;
|
||||
if(boostSort == null || !boostSort){
|
||||
SortField sortField = new SortField(default_primary_key, SortField.Type.INT, true);
|
||||
Sort sort = new Sort(sortField);
|
||||
sort = new Sort(sortField);
|
||||
}
|
||||
|
||||
//装配解析结果 指定读取量级
|
||||
TopDocs search = indexSearcher.search(query, max_select_count, sort);
|
||||
TopDocs search = sort == null ? indexSearcher.search(query, max_select_count) : indexSearcher.search(query, max_select_count, sort);
|
||||
|
||||
//获得数据地址数组
|
||||
ScoreDoc[] scoreDocs = search.scoreDocs;
|
||||
@ -265,6 +262,7 @@ public class LuceneIndexUtils {
|
||||
end = scoreDocs.length;
|
||||
}
|
||||
for (int i = start; i < end; i++) {
|
||||
//System.out.println(scoreDocs[i].score);
|
||||
//进集合 装配
|
||||
list.add(indexSearcher.doc(scoreDocs[i].doc));
|
||||
}
|
||||
|
@ -24,7 +24,9 @@
|
||||
<result property="title" column="title" />
|
||||
<result property="content" column="content" />
|
||||
<result property="key" column="key" />
|
||||
<result property="titleContentIndex" column="title_content_index" />
|
||||
<result property="key" column="key" />
|
||||
<result property="showFlag" column="show_flag" />
|
||||
<result property="createTime" column="create_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysNutritionQuestionVo">
|
||||
@ -98,7 +100,7 @@
|
||||
|
||||
<!-- 根据关键词查询对应知识问题 -->
|
||||
<select id="getNutritionQuestionListByKey" parameterType="SysNutritionQuestion" resultMap="SysNutritionQuestionResultExtended">
|
||||
select id, title, `key`, content where del_flag = 0
|
||||
select id, title, `key`, content, show_flag, create_time where del_flag = 0
|
||||
<if test="showFlag != null "> and show_flag = #{showFlag}</if>
|
||||
<if test="key != null and key != ''">
|
||||
and (title like CONCAT('%',#{key},'%') or key like CONCAT('%',#{key},'%') or titleContentIndex like CONCAT('%',#{key},'%'))
|
||||
@ -117,4 +119,14 @@
|
||||
select * from sys_nutrition_question where del_flag = 0 order by id asc limit #{start},#{pageSize}
|
||||
</select>
|
||||
|
||||
|
||||
<update id="updateWxShowByIds">
|
||||
update sys_nutrition_question set show_flag = #{wxShow} where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
@ -51,3 +51,12 @@ export function exportNutritionQuestion(query) {
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
//更新营养知识小问答的展示状态
|
||||
export function updateWxShow(data){
|
||||
return request({
|
||||
url: '/custom/nutritionQuestion/updateWxShow',
|
||||
method: 'get',
|
||||
params: data
|
||||
})
|
||||
}
|
@ -7,9 +7,20 @@
|
||||
placeholder="请输入关键词"
|
||||
clearable
|
||||
size="small"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="展示状态" prop="showFlag">
|
||||
<el-select
|
||||
v-model="queryParams.showFlag"
|
||||
placeholder="请选择展示状态"
|
||||
clearable
|
||||
size="small"
|
||||
>
|
||||
<el-option key="0" label="不展示" value="0"/>
|
||||
<el-option key="1" label="展示" value="1"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
|
||||
<el-form-item>
|
||||
<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
@ -81,6 +92,18 @@
|
||||
<!--<AutoHideMessage :data="scope.row.content == null ? '' : (scope.row.content+'')" :maxLength="10"/>-->
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="小程序展示状态" align="center" prop="wxShow" >
|
||||
<template slot-scope="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.wxShow"
|
||||
active-text="展示"
|
||||
inactive-text="不展示"
|
||||
@change="handleWxShow($event, scope.row)"
|
||||
>
|
||||
</el-switch>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
@ -141,20 +164,16 @@
|
||||
<el-form-item label="内容" prop="content">
|
||||
<Editor :value="form.content" :isClear="isClear" @change="questionContentChange"></Editor>
|
||||
</el-form-item>
|
||||
<!--<el-form-item label="内容" prop="content" >
|
||||
<el-input
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
maxlength="1000"
|
||||
show-word-limit
|
||||
placeholder="请输入内容"
|
||||
v-model="form.content">
|
||||
</el-input>
|
||||
</el-form-item>-->
|
||||
|
||||
<!-- <el-form-item label="关键词" prop="key">
|
||||
<el-input v-model="form.key" placeholder="请输入关键词" />
|
||||
</el-form-item>-->
|
||||
<el-form-item label="展示状态" prop="wxShow">
|
||||
<el-switch
|
||||
v-model="form.wxShow"
|
||||
active-text="小程序展示"
|
||||
inactive-text="小程序不展示">
|
||||
</el-switch>
|
||||
<div>提示:请保证内容正确再展示到小程序</div>
|
||||
</el-form-item>
|
||||
|
||||
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
@ -171,7 +190,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listNutritionQuestion, getNutritionQuestion, delNutritionQuestion, addNutritionQuestion, updateNutritionQuestion, exportNutritionQuestion } from "@/api/custom/nutritionQuestion";
|
||||
import { listNutritionQuestion, getNutritionQuestion, delNutritionQuestion, addNutritionQuestion, updateNutritionQuestion, exportNutritionQuestion,updateWxShow } from "@/api/custom/nutritionQuestion";
|
||||
import Editor from '@/components/Wangeditor';
|
||||
import AutoHideMessage from "@/components/AutoHideMessage";
|
||||
export default {
|
||||
@ -201,7 +220,8 @@ export default {
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
key: null
|
||||
key: null,
|
||||
showFlag: null
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
@ -231,6 +251,9 @@ export default {
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listNutritionQuestion(this.queryParams).then(response => {
|
||||
response.data.data.forEach(element => {
|
||||
element.wxShow = element.showFlag == 1 ? true : false;
|
||||
});
|
||||
this.nutritionQuestionList = response.data.data;
|
||||
this.total = response.data.total;
|
||||
this.loading = false;
|
||||
@ -248,7 +271,9 @@ export default {
|
||||
title: null,
|
||||
content: null,
|
||||
key: null,
|
||||
keyArray: []
|
||||
keyArray: [],
|
||||
wxShow: false,
|
||||
showFlag: 0
|
||||
};
|
||||
this.resetForm("form");
|
||||
},
|
||||
@ -263,6 +288,11 @@ export default {
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
this.queryParams = {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
key: ""
|
||||
}
|
||||
this.resetForm("queryForm");
|
||||
this.handleQuery();
|
||||
},
|
||||
@ -294,7 +324,9 @@ export default {
|
||||
title: response.data.title,
|
||||
content: response.data.content,
|
||||
key: response.data.key,
|
||||
keyArray: response.data.key.split(",")
|
||||
keyArray: (response.data.key != null && response.data.key.trim() != '' ) ? response.data.key.split(",") : null,
|
||||
showFlag: response.data.showFlag,
|
||||
wxShow: response.data.showFlag == 1 ? true : false
|
||||
}
|
||||
//this.form.keyArray = response.data.key.split(","),
|
||||
this.open = true;
|
||||
@ -311,6 +343,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
this.form.key = this.form.keyArray.join(",");
|
||||
this.form.showFlag = this.form.wxShow ? 1 : 0;
|
||||
if (this.form.id != null) {
|
||||
updateNutritionQuestion(this.form).then(response => {
|
||||
if (response.code === 200) {
|
||||
@ -357,6 +390,13 @@ export default {
|
||||
}).then(response => {
|
||||
this.download(response.msg);
|
||||
}).catch(function() {});
|
||||
},
|
||||
handleWxShow(newWxshow, row){
|
||||
let param = {
|
||||
id: row.id,
|
||||
showFlag: newWxshow ? 1 : 0
|
||||
};
|
||||
updateWxShow(param);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user