|
@@ -2,35 +2,92 @@
|
|
|
* 知识库
|
|
|
*/
|
|
|
|
|
|
-import { Text, View } from "@tarojs/components";
|
|
|
+import { Text, View,Image, ScrollView } from "@tarojs/components";
|
|
|
|
|
|
import PageCustom from "@/components/page-custom/index";
|
|
|
import NavBarNormal from "@/components/nav-bar-normal/index";
|
|
|
+import BottomBar from "@/components/BottomBar";
|
|
|
import FigureListItem from "@/components/list/figure-list-item";
|
|
|
import IconFIleTxt from "@/components/icon/IconFIleTxt";
|
|
|
import IconEye from "@/components/icon/IconEye";
|
|
|
import IconA from "@/components/icon/IconA";
|
|
|
import IconQ from "@/components/icon/IconQ";
|
|
|
import WemetaSwitch from "@/components/wemeta-switch";
|
|
|
-import { useState } from "react";
|
|
|
+import { useEffect, useState } from "react";
|
|
|
import CardEditable from "@/components/card/card-editable/index";
|
|
|
-import Taro from "@tarojs/taro";
|
|
|
+import Taro, { useRouter } from "@tarojs/taro";
|
|
|
+import { getMyKnowledgeDetail, deleteKnowledgeQa, updateExactAnswer } from "@/service/knowledge";
|
|
|
+import { TKnowledgeDetail } from "@/types/knowledge";
|
|
|
+import { isSuccess } from "@/utils";
|
|
|
+import { useModalStore } from "@/store/modalStore";
|
|
|
+import style from './index.module.less'
|
|
|
|
|
|
export default function Index() {
|
|
|
+ const router = useRouter()
|
|
|
+ const { knowledgeId } = router.params
|
|
|
const [checked, setChecked] = useState(false);
|
|
|
- const handleEdit = ()=> {
|
|
|
+ const [detail, setDetail] = useState<TKnowledgeDetail|null>(null)
|
|
|
+
|
|
|
+ const { showModal } = useModalStore()
|
|
|
+
|
|
|
+ const handleEdit = (qaId: number)=> {
|
|
|
Taro.navigateTo({
|
|
|
- url: '/pages/knowledge-item-editor/index'
|
|
|
+ url: `/pages/knowledge-item-editor/index?knowledgeId=${knowledgeId}&qaId=${qaId}`
|
|
|
})
|
|
|
}
|
|
|
+ // 删除问答项
|
|
|
+ const handleDeleteItem = async (qaId: number)=> {
|
|
|
+ if(!detail){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ showModal({
|
|
|
+ content: '确定删除该问答项吗?',
|
|
|
+ onConfirm: async () => {
|
|
|
+ const { status } = await deleteKnowledgeQa(detail.knowledgeId, qaId)
|
|
|
+ if(isSuccess(status)){
|
|
|
+ Taro.showToast({title: '删除成功', icon: 'success'})
|
|
|
+ getDetail(detail.knowledgeId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取详情
|
|
|
+ const getDetail = async (knowledgeId: number)=> {
|
|
|
+ const response = await getMyKnowledgeDetail(knowledgeId)
|
|
|
+ if(isSuccess(response.status) && response.data){
|
|
|
+ setDetail(response.data)
|
|
|
+ setChecked(response.data.enableExactAnswer)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开启/关闭 精准问答模式
|
|
|
+ const handleEnableExactAnswer = async () => {
|
|
|
+ if(!detail?.knowledgeId){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const {status} = await updateExactAnswer(detail.knowledgeId, !checked)
|
|
|
+ if(isSuccess(status)){
|
|
|
+ setChecked(!checked)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ useEffect(()=> {
|
|
|
+ knowledgeId && getDetail(parseInt(knowledgeId))
|
|
|
+ }, [knowledgeId])
|
|
|
+
|
|
|
return (
|
|
|
<PageCustom>
|
|
|
<NavBarNormal backText="知识库"></NavBarNormal>
|
|
|
- <View className="w-full">
|
|
|
+ <View className="w-full overflow-hidden">
|
|
|
<View className="p-16">
|
|
|
<View className="mb-16">
|
|
|
<FigureListItem
|
|
|
- figure={IconFIleTxt}
|
|
|
+ figure={()=> {
|
|
|
+ return <>{detail?.icon && <Image src={detail?.icon} mode="widthFix" style={{width: '36px', height: '36px'}}></Image>}</>
|
|
|
+ }}
|
|
|
rightRenderer={() => (
|
|
|
<View>
|
|
|
<IconEye />
|
|
@@ -38,9 +95,9 @@ export default function Index() {
|
|
|
)}
|
|
|
>
|
|
|
<View className="flex flex-col flex-1 gap-2 w-full">
|
|
|
- <View className="text-14 leading-22">飞秒小知识</View>
|
|
|
+ <View className="text-14 leading-22 truncate">{detail?.title}</View>
|
|
|
<View className="text-12 leading-20 text-gray-45">
|
|
|
- 03-24 12:20 | 822.KB
|
|
|
+ {detail?.createTime} | {detail?.fileSizeStr}
|
|
|
</View>
|
|
|
</View>
|
|
|
</FigureListItem>
|
|
@@ -58,18 +115,55 @@ export default function Index() {
|
|
|
<View className="flex-center">
|
|
|
<WemetaSwitch
|
|
|
checked={checked}
|
|
|
- onChange={(checked) => setChecked(checked)}
|
|
|
+ onChange={handleEnableExactAnswer}
|
|
|
></WemetaSwitch>
|
|
|
</View>
|
|
|
</View>
|
|
|
</View>
|
|
|
- <View>
|
|
|
+
|
|
|
+
|
|
|
+ <View className="pb-100">
|
|
|
<View className="rounded-container-header">
|
|
|
<View className="text-14 font-medium leading-22 px-16 pb-16">
|
|
|
- 问答列表共<Text className="text-primary">10</Text>条
|
|
|
+ 问答列表共<Text className="text-primary">{detail?.qaList.length}</Text>条
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <View className={style.scrollContainer}>
|
|
|
+ {detail?.qaList.map((item)=> {
|
|
|
+ return <View className="flex flex-col gap-16 px-16 mb-16">
|
|
|
+ <CardEditable buttons={[<View onClick={()=> handleDeleteItem(item.qaId)}>删除</View>, <View onClick={()=> handleEdit(item.qaId)}>编辑</View>]}>
|
|
|
+ <View className="flex items-start mb-8 gap-8">
|
|
|
+ <View className="flex-center h-28"><IconQ/></View>
|
|
|
+ <View className="flex-1 font-medium text-14 leading-28">{item.questions[0]}</View>
|
|
|
+ </View>
|
|
|
+
|
|
|
+ <View className="flex items-start gap-8">
|
|
|
+ <View className="flex-center h-28"><IconA/></View>
|
|
|
+ <View className="flex-1 text-12 leading-20 text-gray-45 truncate">
|
|
|
+ <View className="truncate">{item.answer}</View>
|
|
|
+
|
|
|
+ {(!!item.links.length) && <View className="pb-12">
|
|
|
+ {item.links.map((link)=> {
|
|
|
+ return <View>查看链接 <Text>{link}</Text></View>
|
|
|
+ })}
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ {(!!item.pics.length) && <View className="pb-12">
|
|
|
+ {item.pics.map((pic)=> {
|
|
|
+ return <View>
|
|
|
+ <Image src={pic} mode="widthFix" className="w-full"></Image>
|
|
|
+ </View>
|
|
|
+ })}
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+
|
|
|
+ </CardEditable>
|
|
|
</View>
|
|
|
+ })}
|
|
|
</View>
|
|
|
- <View className="flex flex-col gap-16 px-16">
|
|
|
+ {/* <View className="flex flex-col gap-16 px-16">
|
|
|
<CardEditable buttons={[<View>删除</View>, <View onClick={handleEdit}>编辑</View>]}>
|
|
|
<View className="flex items-start mb-8 gap-8">
|
|
|
<View className="flex-center h-28"><IconQ/></View>
|
|
@@ -82,14 +176,13 @@ export default function Index() {
|
|
|
</View>
|
|
|
|
|
|
</CardEditable>
|
|
|
- </View>
|
|
|
- </View>
|
|
|
- <View className="bottom-bar">
|
|
|
- <View className="flex gap-8 px-20 py-12">
|
|
|
- <View className="button-rounded button-plain button-warn w-88">删除</View>
|
|
|
- <View className="button-rounded button-primary flex-1">共享到企业知识</View>
|
|
|
- </View>
|
|
|
+ </View> */}
|
|
|
</View>
|
|
|
+ <BottomBar>
|
|
|
+ <View className="button-rounded button-plain button-warn w-88">删除</View>
|
|
|
+ <View className="button-rounded button-primary flex-1">共享到企业知识</View>
|
|
|
+ </BottomBar>
|
|
|
+
|
|
|
</View>
|
|
|
</PageCustom>
|
|
|
);
|