index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. import {
  2. computed,
  3. defineComponent,
  4. nextTick,
  5. reactive,
  6. ref,
  7. Teleport,
  8. toRef
  9. } from 'vue';
  10. import styles from './index.module.less';
  11. import {
  12. ImageRenderToolbarProps,
  13. NCollapse,
  14. NCollapseItem,
  15. NImage,
  16. NImageGroup,
  17. NSpace,
  18. NSpin
  19. } from 'naive-ui';
  20. import arrow from './images/arrow.png';
  21. import TheSearch from '../../TheSearch';
  22. import {
  23. api_sysTeacherManual_detail,
  24. api_sysTeacherManualPage
  25. } from '/src/api/user';
  26. import TheEmpty from '../../TheEmpty';
  27. import VideoModal from '../../card-preview/video-modal';
  28. import useDrag from './guide-drag';
  29. import { onBeforeRouteUpdate, useRoute } from 'vue-router';
  30. /** 功能引导 */
  31. export default defineComponent({
  32. name: 'guide-section',
  33. setup(props, { expose }) {
  34. const route = useRoute();
  35. // 操作记录
  36. const opInfo = reactive({
  37. showGuide: false, // 是否显示
  38. routePath: route.path === '/' ? '/Home' : route.path,
  39. searchValue: '',
  40. collapseId: [], // 默认展开哪个
  41. dataList: [] as any[], // 手册列表
  42. manualDetail: {} as any, // 详情
  43. detailLoading: false // 加载详情
  44. });
  45. const previewShow = ref(false);
  46. const previewUrl = ref('');
  47. const previewImgList = ref<string[]>([]);
  48. const guideBoxClass = 'guideBoxClass_drag';
  49. const { styleDrag, windowInfo, onScreen, onResize, onReset } = useDrag(
  50. [`${guideBoxClass} .guideTitle`],
  51. guideBoxClass,
  52. toRef(opInfo, 'showGuide')
  53. );
  54. const videoBoxClass = 'videoBoxClass_drag';
  55. const videoBoxData = useDrag(
  56. [`${videoBoxClass} .guideTitleVideo`],
  57. videoBoxClass,
  58. previewShow,
  59. {
  60. resizeDirection: [true, true, true, true, true, true, true, true],
  61. minHeight: 391.5,
  62. minWidth: 600,
  63. defaultPosition: 'center',
  64. width: 864,
  65. height: 540
  66. }
  67. );
  68. const titleName = computed(() => {
  69. let name = '操作手册';
  70. if (
  71. windowInfo.showType === 'CONTENT' &&
  72. windowInfo.windowType === 'SMALL'
  73. ) {
  74. name = opInfo.manualDetail?.name || '返回';
  75. }
  76. return name;
  77. });
  78. /** 操作窗口状态 */
  79. const onToggle = () => {
  80. opInfo.showGuide = !opInfo.showGuide;
  81. if (!opInfo.showGuide) {
  82. previewShow.value = false;
  83. videoBoxData.onReset();
  84. }
  85. };
  86. /** 操作视频窗口状态 */
  87. const onToggleVideo = () => {
  88. previewShow.value = !previewShow.value;
  89. if (!previewShow.value) videoBoxData.onReset();
  90. };
  91. const onClickItem = async (item: any) => {
  92. opInfo.detailLoading = true;
  93. try {
  94. windowInfo.showType = 'CONTENT';
  95. await getTeacherManualDetail(item.id);
  96. } catch {
  97. //
  98. }
  99. opInfo.detailLoading = false;
  100. };
  101. // 点击菜单
  102. const onClickMenu = () => {
  103. if (windowInfo.windowType === 'LARGE') return;
  104. windowInfo.showType = 'MENU';
  105. };
  106. /** 获取操作手册 */
  107. const getTeacherManual = async () => {
  108. try {
  109. const { data } = await api_sysTeacherManualPage({
  110. keyword: opInfo.searchValue,
  111. permission: opInfo.routePath
  112. });
  113. opInfo.dataList = data || [];
  114. opInfo.manualDetail = {};
  115. const id: any = opInfo.dataList[0]?.id;
  116. if (id) {
  117. opInfo.collapseId = id;
  118. const firstChildId = opInfo.dataList[0]?.children[0]?.id;
  119. getTeacherManualDetail(firstChildId);
  120. }
  121. } catch {
  122. //
  123. }
  124. };
  125. /** 获取详情 */
  126. const getTeacherManualDetail = async (id: string) => {
  127. try {
  128. if (id === opInfo.manualDetail?.id) return;
  129. const { data } = await api_sysTeacherManual_detail(id);
  130. let opFlow = data.opFlow || '';
  131. opFlow = opFlow.replace(
  132. /<img/gi,
  133. '<img class="manualImg" onClick="onLookImg(this)"'
  134. );
  135. opFlow = opFlow.replace(
  136. /<video/gi,
  137. '<div class="videoSection"><video class="manualVideo" onClick="onLookVideo(this)" '
  138. );
  139. opFlow = opFlow.replace(/<\/video>/gi, '</video></div>');
  140. opFlow = opFlow.replace(/controls/gi, 'c');
  141. data.opFlow = opFlow;
  142. opInfo.manualDetail = data || {};
  143. nextTick(() => {
  144. // const manualImg = document.querySelector('.manualImg')
  145. const domList = document.querySelectorAll('.manualImg');
  146. const imgList: any[] = [];
  147. domList.forEach((item: any) => {
  148. imgList.push(item.src);
  149. });
  150. previewImgList.value = imgList;
  151. });
  152. } catch {
  153. //
  154. }
  155. };
  156. getTeacherManual();
  157. onBeforeRouteUpdate((route: any) => {
  158. if (route.path !== opInfo.routePath) {
  159. opInfo.showGuide = false;
  160. previewShow.value = false;
  161. onReset();
  162. opInfo.routePath = route.path === '/' ? '/Home' : route.path;
  163. windowInfo.showType = 'MENU';
  164. opInfo.searchValue = '';
  165. getTeacherManual();
  166. }
  167. });
  168. expose({
  169. onToggle
  170. });
  171. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  172. // @ts-ignore
  173. window.onLookImg = (target: any) => {
  174. const index = previewImgList.value.findIndex(
  175. (src: string) => target.src === src
  176. );
  177. const nImage = document.querySelectorAll('.rightGuide .n-image')[index];
  178. const img: any = nImage.querySelector('img');
  179. img.click();
  180. // 默认关闭视频
  181. previewShow.value = false;
  182. videoBoxData.onReset();
  183. };
  184. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  185. // @ts-ignore
  186. window.onLookVideo = (target: any) => {
  187. const sourceElement = target.querySelector('source');
  188. const videoSrc = sourceElement ? sourceElement.src : null;
  189. previewUrl.value = videoSrc;
  190. previewShow.value = true;
  191. };
  192. return () => (
  193. <Teleport to={'body'}>
  194. <div
  195. class={[
  196. styles['drag-wrapper-draggable'],
  197. !opInfo.showGuide ? styles.draggleClose : ''
  198. ]}>
  199. <div
  200. class={[styles.guideSection, guideBoxClass]}
  201. style={{
  202. ...styleDrag.value,
  203. borderRadius: windowInfo.windowType === 'LARGE' ? '16px' : ''
  204. }}>
  205. <div class={styles.guideCenter}>
  206. <div class={[styles.guideTitle, 'guideTitle']}>
  207. <div class={styles.name} onClick={onClickMenu}>
  208. {windowInfo.showType === 'CONTENT' &&
  209. windowInfo.windowType === 'SMALL' && (
  210. <i class={styles.back}></i>
  211. )}
  212. {titleName.value}
  213. </div>
  214. <div class={styles.operation}>
  215. <i
  216. class={[
  217. styles.screen,
  218. windowInfo.windowType === 'LARGE'
  219. ? styles.screenSmall
  220. : ''
  221. ]}
  222. onClick={onScreen}></i>
  223. <i
  224. class={[
  225. styles.resize,
  226. windowInfo.currentType === 'SMALL'
  227. ? styles.resizeLarge
  228. : ''
  229. ]}
  230. onClick={onResize}></i>
  231. <i class={styles.close} onClick={onToggle}></i>
  232. </div>
  233. </div>
  234. <div
  235. class={[
  236. styles.container,
  237. windowInfo.windowType === 'LARGE'
  238. ? styles.windowContainer
  239. : ''
  240. ]}>
  241. <div
  242. class={styles.leftGuide}
  243. style={{
  244. display:
  245. windowInfo.showType === 'MENU' ||
  246. windowInfo.windowType === 'LARGE'
  247. ? 'block'
  248. : 'none'
  249. }}>
  250. <div
  251. style={{
  252. height: opInfo.dataList.length <= 0 ? '100%' : 'auto'
  253. }}>
  254. <div class={styles.searchContainer}>
  255. <TheSearch
  256. round={false}
  257. v-model:value={opInfo.searchValue}
  258. onSearch={async (val: string) => {
  259. opInfo.searchValue = val;
  260. await getTeacherManual();
  261. if (windowInfo.windowType === 'LARGE') {
  262. const id = opInfo.dataList[0]?.children[0]?.id;
  263. id && getTeacherManualDetail(id);
  264. }
  265. }}
  266. />
  267. </div>
  268. <NCollapse
  269. v-model:expandedNames={opInfo.collapseId}
  270. accordion>
  271. {{
  272. arrow: () => <img class={styles.arrow} src={arrow} />,
  273. default: () =>
  274. opInfo.dataList.map((item: any) => (
  275. <NCollapseItem title={item.name} name={item.id}>
  276. <div class={styles.childList}>
  277. {item.children &&
  278. item.children.map((child: any) => (
  279. <div
  280. class={[
  281. styles.childItem,
  282. windowInfo.windowType === 'LARGE' &&
  283. child.id === opInfo.manualDetail?.id
  284. ? styles.active
  285. : ''
  286. ]}
  287. onClick={() => onClickItem(child)}>
  288. {child.name}
  289. </div>
  290. ))}
  291. </div>
  292. </NCollapseItem>
  293. ))
  294. }}
  295. </NCollapse>
  296. {opInfo.dataList.length <= 0 && (
  297. <div class={styles.emptyDiv}>
  298. <TheEmpty />
  299. </div>
  300. )}
  301. </div>
  302. </div>
  303. <div
  304. class={[styles.rightGuide, 'rightGuide']}
  305. style={{
  306. display:
  307. windowInfo.showType === 'CONTENT' ||
  308. windowInfo.windowType === 'LARGE'
  309. ? 'block'
  310. : 'none'
  311. }}>
  312. {previewImgList.value.length > 0 && (
  313. <NImageGroup
  314. renderToolbar={({ nodes }: ImageRenderToolbarProps) => {
  315. return [
  316. nodes.prev,
  317. nodes.next,
  318. nodes.rotateCounterclockwise,
  319. nodes.rotateClockwise,
  320. nodes.resizeToOriginalSize,
  321. nodes.zoomOut,
  322. nodes.zoomIn,
  323. nodes.close
  324. ];
  325. }}>
  326. <NSpace>
  327. {previewImgList.value.map((src: string) => (
  328. <NImage width="0" src={src}></NImage>
  329. ))}
  330. </NSpace>
  331. </NImageGroup>
  332. )}
  333. <NSpin show={opInfo.detailLoading}>
  334. <div
  335. v-html={opInfo.manualDetail.opFlow}
  336. class-="html-to-dom"></div>
  337. </NSpin>
  338. </div>
  339. </div>
  340. </div>
  341. </div>
  342. <div
  343. class={[styles.videoModal, videoBoxClass]}
  344. style={{
  345. ...videoBoxData.styleDrag.value,
  346. display: previewShow.value ? 'flex' : 'none'
  347. }}>
  348. <div class={[styles.guideTitle, 'guideTitleVideo']}>
  349. <div class={styles.name}>预览</div>
  350. <div class={styles.operation}>
  351. <i class={styles.close} onClick={onToggleVideo}></i>
  352. </div>
  353. </div>
  354. {previewShow.value ? (
  355. <VideoModal
  356. key={previewUrl.value}
  357. title="预览"
  358. src={previewUrl.value}
  359. isDownload={false}
  360. fullscreen
  361. />
  362. ) : (
  363. ''
  364. )}
  365. </div>
  366. </div>
  367. </Teleport>
  368. );
  369. }
  370. });