1
litian
2024-05-15 82b611ce9b9ee9aec96ef945da785e9ef6b5e602
src/views/home.vue
@@ -321,12 +321,14 @@
              <div><img :src="zoomOut" @click="changePageSize('reduce')" /></div>
            </div>
            <div class="brushImgBox">
              <div><img :src="huabi2" class="brushImg" />画笔</div>
              <div @click="jumpContent('note' + index)">
                <img :src="huabi2" class="brushImg" />画笔
              </div>
            </div>
          </div>
        </div>
        <!-- 微应用盒子 -->
        <div class="pageBox-content" @scroll="pageScroll">
        <div class="pageBox-content">
          <div class="content-box">
            <div
              id="container"
@@ -737,17 +739,17 @@
        v-for="item in colorSelectList"
        :key="item.key"
        class="flex1 hover"
        @click="clickSelect(item)"
        @click="clickSelectColor(item)"
      >
        <div :style="{ background: item.key }" class="scribeItem">
          <img :src="xuanzhong" v-if="item.key == colorActive" />
          <img :src="xuanzhong" v-if="item.key == noteColorActive" />
        </div>
      </div>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="addNote">确 定</el-button>
        <el-button type="primary" @click="addUserKey">确 定</el-button>
      </span>
    </template>
  </el-dialog>
@@ -827,6 +829,7 @@
import useClipboard from 'vue-clipboard3'
const { toClipboard } = useClipboard()
const request = inject('request')
const toolClass = inject('toolClass')
const qiankunActions = inject('qiankunActions')
//获取路由器
let router = useRouter()
@@ -938,6 +941,7 @@
let microApp = null // 微应用实例
const bookName = ref('')
const bookId = ref(1)
const activeCatalog = ref()
onMounted(() => {
  getCatalogueData()
  getResourceData()
@@ -959,9 +963,10 @@
  // 加载微应用
  microApp = loadMicroApp(microApps.book1, {
    sandbox: {
      // strictStyleIsolation: true,
      strictStyleIsolation: true
      // experimentalStyleIsolation: true
    }
    },
    singular: true
  })
  window.qiankunActions.onGlobalStateChange((state, prev) => {
@@ -978,9 +983,15 @@
    windowSelection: (data) => {
      // 绑定子应用选择监听事件
      console.log(data, '子应用选择')
      getSelection(data)
      if(data.txt){
        getSelection(data)
      }else{
        showToolBox.value = false
      }
    },
    catalogChange: (data) => {
      activeCatalog.value = data.showCatalogList
      getSignData()
      console.log(data, '章节切换:目前显示的三个章节')
    },
    pageChange: (data) => {
@@ -991,9 +1002,9 @@
      //   catalogName: "",
      // }
      console.log(data, '页面切换:目前显示页面和对应的章节信息')
    }
    },
  })
  // 调用子层方法
  // if (window.qiankunState && window.qiankunState.aa) window.qiankunState.aa(1)
})
@@ -1011,10 +1022,10 @@
watch(
  () => bookId.value,
  (val) => {
    getNotesList() // 获取笔记
    getlineHeightList() //获取高亮
    getScribeList() //获取划线
    getScreenshotList() //截图
    // getNotesList() // 获取笔记
    // getlineHeightList() //获取高亮
    // getScribeList() //获取划线
    // getScreenshotList() //截图
  }
)
//获取目录
@@ -1693,14 +1704,13 @@
//选中文字工具栏
const selectText = ref('') //选中文字
const selectNode = ref(null)
const selectPage = ref(1)
const showToolBox = ref(false)
const dialogToolData = reactive({
  left: 500,
  top: 300,
  txt: '',
  page: '',
  chapter: '', //选中文字所在章节
  parentNode: null,
  lineHeight: [], //高亮
  scribeList: [], //划线
  notesList: [] //笔记
@@ -1709,30 +1719,18 @@
///内容选中
const getSelection = (data) => {
  if (data.txt) {
    console.log(data.node, 'data')
    dialogToolData.txt = data.txt
    dialogToolData.page = data.page
    dialogToolData.chapter = data.chapterNum
    dialogToolData.left = data.x
    dialogToolData.top = data.y
    showToolBox.value = true
    selectText.value = data.txt
    selectNode.value = data.node.innerHTML
    selectPage.value = data.page
  }
}
const pageScroll = (e) => {
  // window.qiankunActions.setGlobalState({
  //   gotoPage: (t, s) => {
  //     // 绑定子应用选择监听事件
  //     console.log(t, s, '子应用滚动')
  //   }
  // })
  showToolBox.value = false
  lineDelete.showLineDelete = false
  // let scroll = e.target.scrollTop
  // let offsetHeight = document.getElementById('container').offsetHeight
  // headerData.process = Math.round((scroll / offsetHeight) * 100)
}
const toolActive = ref('')
const colorActive = ref('')
const noteColorActive = ref('')
const dialogToolList = reactive([
  { icon: gaoliang, activeIcon: gaoliang1, name: '高亮' },
  { icon: huaxian, activeIcon: huaxian1, name: '划线' },
@@ -1897,239 +1895,176 @@
const clickSelect = (item) => {
  colorActive.value = item.key
  if (toolActive.value == '高亮') {
    let lineHeightData = {
      selectNode: selectNode.value,
      selectText: selectText.value,
      selectPage: selectPage.value,
      color: colorActive.value,
      chapter: dialogToolData.chapter,
      createDate: new Date()
    }
    dialogToolData.lineHeight.push(lineHeightData)
    console.log(dialogToolData.lineHeight, '前node')
    request({
      url: '/identity/api/ApiAppUserSetKey',
      method: 'post',
      data: {
        setKeyRequests: [
          {
            domain: 'highLight',
            key: bookId.value,
            value: JSON.stringify(dialogToolData.lineHeight)
          }
        ]
      }
    }).then((res) => {
      showToolBox.value = false
      colorActive.value = ''
      toolActive.value = ''
      getlineHeightList()
    })
  }
  if (toolActive.value == '划线') {
    dialogToolData.scribeList.push({
      selectNode: selectNode.value,
      selectText: selectText.value,
      selectPage: selectPage.value,
      color: colorActive.value,
      chapter: dialogToolData.chapter,
      createDate: new Date()
    })
    request({
      url: '/identity/api/ApiAppUserSetKey',
      method: 'post',
      data: {
        setKeyRequests: [
          {
            domain: 'underline',
            key: bookId.value,
            value: JSON.stringify(dialogToolData.scribeList)
          }
        ]
      }
    }).then((res) => {
      colorActive.value = ''
      showToolBox.value = false
      toolActive.value = ''
      getScribeList()
    })
  }
  addUserKey()
}
//笔记选颜色
const clickSelectColor = (item) => {
  noteColorActive.value = item.key
}
const lock = ref(false)
const addNote = () => {
  const obj = {
    desc: formData.desc
  }
  if (!colorActive.value) {
    ElMessage.error('请选择笔记颜色!')
    return
  }
  if (!lock.value) {
    lock.value = true
    if (formData.desc.replace(/^\s*|\s*$/g, '')) {
      dialogToolData.notesList.push({
        selectNode: selectNode.value,
        selectText: selectText.value,
        color: colorActive.value,
        selectPage: selectPage.value,
        chapter: dialogToolData.chapter,
const addUserKey = () => {
  let dom = ''
  let data = null
  switch (toolActive.value) {
    case '高亮':
      dom = 'highLightData-' + bookId.value
      data = dialogToolData.lineHeight[dialogToolData.chapter]
      data.push({
        id: toolClass.uuid(8),
        txt: dialogToolData.txt,
        page: dialogToolData.page,
        type: 'Highlight',
        color: colorActive.value
      })
      break
    case '划线':
      dom = 'underline-' + bookId.value
      data = dialogToolData.scribeList[dialogToolData.chapter]
      data.push({
        id: toolClass.uuid(8),
        txt: dialogToolData.txt,
        page: dialogToolData.page,
        type: 'Dashing',
        color: colorActive.value
      })
      break
    case '笔记':
      if (!formData.desc.replace(/^\s*|\s*$/g, '')) {
        ElMessage.error('笔记内容不能为空!')
        return
      }
      if (!noteColorActive.value) {
        ElMessage.error('请选择笔记颜色!')
        return
      }
      dom = 'notes-' + bookId.value
      data = dialogToolData.notesList.length != 0 ? dialogToolData.notesList[dialogToolData.chapter] : []
      data.push({
        id: toolClass.uuid(8),
        txt: dialogToolData.txt,
        page: dialogToolData.page,
        type: 'Note',
        color: noteColorActive.value,
        createDate: new Date(),
        note: formData.desc.replace(/^\s*|\s*$/g, '')
      })
      request({
        url: '/identity/api/ApiAppUserSetKey',
        method: 'post',
        data: {
          setKeyRequests: [
            {
              domain: 'notes',
              key: bookId.value,
              value: JSON.stringify(dialogToolData.notesList)
            }
          ]
        }
      }).then((res) => {
        showToolBox.value = false
        addNoteVisble.value = false
        colorActive.value = ''
        toolActive.value = ''
        getNotesList()
        setTimeout(() => {
          lock.value = false
        }, 1000)
      })
    } else {
      ElMessage.error('笔记内容不能为空!')
      lock.value = false
    }
      break
  }
}
//笔记
const getNotesList = () => {
  scribeData.noteList = []
  scribeData.loading = true
  request({
    url: '/identity/api/ApiGetAppUserKey',
    url: '/identity/api/ApiAppUserSetKey',
    method: 'post',
    data: {
      domain: 'notes',
      keys: [bookId.value]
    }
  })
    .then((res) => {
      if (res && res.length > 0 && res[0].value) {
        dialogToolData.notesList = JSON.parse(res[0].value)
        let list = JSON.parse(res[0].value)
        let textDom1 = document.querySelector('.temp-book')
        if (list.length > 0) {
          list.forEach((item, index) => {
            item.createDate = moment(item.createDate).format('YYYY-MM-DD')
            if (searchText.value) {
              searchText.value = searchText.value.replace(/^\s*|\s*$/g, '')
              let text = searchText.value.replace(/^\s*|\s*$/g, '')
              if (item.text.indexOf(text) > -1) {
                if (menuState.notesColor == 'all') {
                  scribeData.noteList.push(item)
                } else if (menuState.notesColor == item.color) {
                  scribeData.noteList.push(item)
                }
              }
            } else {
              if (menuState.notesColor == 'all') {
                scribeData.noteList.push(item)
              } else if (menuState.notesColor == item.color) {
                scribeData.noteList.push(item)
              }
            }
            //页面添加笔记
            let rReg1 = new RegExp(`${item.selectText}`, 'ig')
            let text1 = textDom1.innerHTML
            let nHtmlText1 = item.selectNode
            let nHtml1 = ''
            nHtml1 = nHtmlText1.replace(
              rReg1,
              `<span style="padding-bottom:2px; border-bottom: 2px solid;border-bottom-color:${item.color}" class="notesline">${item.selectText}</span><img src="${biji1}" style="cursor: pointer" onclick="notesVisbleShow('${item.selectText}')"/>`
            )
            let rHtml1 = ''
            rHtml1 = text1.replace(nHtmlText1, nHtml1)
            textDom1.innerHTML = rHtml1
          })
      setKeyRequests: [
        {
          domain: dom,
          key: dialogToolData.chapter,
          value: JSON.stringify(data)
        }
      }
      scribeData.loading = false
    })
    .catch((err) => {
      scribeData.loading = false
    })
}
//划线
const getScribeList = () => {
  scribeData.scribeDataList = []
  request({
    url: '/identity/api/ApiGetAppUserKey',
    method: 'post',
    data: {
      domain: 'underline',
      keys: [bookId.value]
      ]
    }
  }).then((res) => {
    if (res && res.length > 0 && res[0].value) {
      dialogToolData.scribeList = JSON.parse(res[0].value)
      scribeData.scribeDataList = JSON.parse(res[0].value)
      let textDom1 = document.querySelector('.temp-book')
      if (scribeData.scribeDataList.length > 0) {
        for (let i = 0; i < scribeData.scribeDataList.length; i++) {
          let item = scribeData.scribeDataList[i]
          let rReg1 = new RegExp(`${item.selectText}`, 'ig')
          let text1 = textDom1.innerHTML
          let nHtmlText1 = item.selectNode
    showToolBox.value = false
    colorActive.value = ''
    noteColorActive.value = ''
    toolActive.value = ''
    getSignData()
  })
}
          let nHtml1 = ''
          nHtml1 = nHtmlText1.replace(
            rReg1,
            `<span style="text-decoration:underline;text-decoration-style: wavy;text-underline-thickness:2px;text-decoration-color:${item.color};cursor: pointer" class="underline" onclick="deleteScribeShow('${item.selectText}')">${item.selectText}</span>`
          )
          let rHtml1 = ''
          rHtml1 = text1.replace(nHtmlText1, nHtml1)
          textDom1.innerHTML = rHtml1
const delUserKey = (type, ids) => {
  switch (type) {
    case 'Highlight':
      dom = 'highLightData-' + bookId.value
      data = dialogToolData.lineHeight
      break
    case 'Dashing':
      dom = 'underline-' + bookId.value
      data = dialogToolData.scribeList
      break
  }
  data = data.filter((item) => ids.indexOf(item.id) == -1)
  request({
    url: '/identity/api/ApiAppUserSetKey',
    method: 'post',
    data: {
      setKeyRequests: [
        {
          domain: dom,
          key: '',
          value: JSON.stringify(data)
        }
      ]
    }
  }).then((res) => {})
}
const getSignData = () => {
  request({
    url: '/identity/api/ApiGetAppUserKey',
    method: 'post',
    data: {
      domain: 'highLightData-' + bookId.value,
      keys: activeCatalog.value.map((item) => item + '')
    }
  }).then((res) => {
    if (res && res.length > 0) {
      for (let i = 0; i < res.length; i++) {
        const item = res[i]
        const data = JSON.parse(item.value)
        // 储值
        dialogToolData.lineHeight[item.key] = data
        // 渲染
        for (let j = 0; j < data.length; j++) {
          const citem = data[j]
          if (window.qiankunState && window.qiankunState.renderSign)
            window.qiankunState.renderSign(citem.type, citem)
        }
      }
    }
  })
}
//高亮
const getlineHeightList = () => {
  scribeData.lineHeightList = []
  request({
    url: '/identity/api/ApiGetAppUserKey',
    method: 'post',
    data: {
      domain: 'highLight',
      keys: [bookId.value]
      domain: 'underline-' + bookId.value,
      keys: activeCatalog.value.map((item) => item + '')
    }
  }).then((res) => {
    if (res && res.length > 0 && res[0].value) {
      dialogToolData.lineHeight = JSON.parse(res[0].value)
      scribeData.lineHeightList = JSON.parse(res[0].value)
      let textDom = document.querySelector('.temp-book')
      if (scribeData.lineHeightList.length > 0) {
        for (let i = 0; i < scribeData.lineHeightList.length; i++) {
          let item = scribeData.lineHeightList[i]
          let rReg = new RegExp(`${item.selectText}`, 'ig')
          let text = textDom.innerHTML
          let nHtmlText = item.selectNode
          let nHtml = ''
          nHtml = nHtmlText.replace(
            rReg,
            `<span style="background: ${item.color};padding:3px;cursor: pointer" class="highLight" onclick="deletelineHeightShow('${item.selectText}')">${item.selectText}</span>`
          )
          // nHtmlText = nHtml
          let rHtml = ''
          rHtml = text.replace(nHtmlText, nHtml)
          textDom.innerHTML = rHtml
    if (res && res.length > 0) {
      for (let i = 0; i < res.length; i++) {
        const item = res[i]
        const data = JSON.parse(item.value)
        // 储值
        dialogToolData.scribeList[item.key] = data
        // 渲染
        for (let j = 0; j < data.length; j++) {
          const citem = data[j]
          if (window.qiankunState && window.qiankunState.renderSign)
            window.qiankunState.renderSign(citem.type, citem)
        }
      }
    }
  })
  request({
    url: '/identity/api/ApiGetAppUserKey',
    method: 'post',
    data: {
      domain: 'notes-' + bookId.value,
      keys: activeCatalog.value.map((item) => item + '')
    }
  }).then((res) => {
    if (res && res.length > 0) {
      for (let i = 0; i < res.length; i++) {
        const item = res[i]
        const data = JSON.parse(item.value)
        // 储值
        dialogToolData.notesList[item.key] = data
        // 渲染
        for (let j = 0; j < data.length; j++) {
          const citem = data[j]
          if (window.qiankunState && window.qiankunState.renderSign)
            window.qiankunState.renderSign(citem.type, citem)
        }
      }
    }
@@ -2242,10 +2177,10 @@
    dialogToolData.notesList.findIndex((itemData) => itemData.selectText == item.selectText),
    1
  )
  selectNode.value = item.selectNode
  selectText.value = item.selectText
  selectPage.value = item.selectPage
  colorActive.value = item.color
  dialogToolData.txt = item.txt
  dialogToolData.page = item.page
  dialogToolData.chapter = item.chapterNum
  noteColorActive.value = item.color
  dialogToolData.chapter = item.chapter
  formData.desc = item.note
  addNoteVisble.value = true