YM
2024-05-15 ac4b8147bb3dbb4cd857be71329b890c2d0fd525
src/views/home.vue
@@ -154,7 +154,7 @@
                    </div>
                  </div>
                  <div
                    class="noteText hover"
                    class="noteText hover 123456"
                    @click="jumpContent('note' + index)"
                    :style="{
                      background:
@@ -317,7 +317,9 @@
              <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>
@@ -823,6 +825,7 @@
import useClipboard from 'vue-clipboard3'
const { toClipboard } = useClipboard()
const request = inject('request')
const toolClass = inject('toolClass')
const qiankunActions = inject('qiankunActions')
//获取路由器
let router = useRouter()
@@ -934,6 +937,7 @@
let microApp = null // 微应用实例
const bookName = ref('')
const bookId = ref(1)
const activeCatalog = ref()
onMounted(() => {
  getCatalogueData()
  getResourceData()
@@ -955,25 +959,45 @@
  // 加载微应用
  microApp = loadMicroApp(microApps.book1, {
    sandbox: {
      // strictStyleIsolation: true,
      strictStyleIsolation: true
      // experimentalStyleIsolation: true
    }
    },
    singular: true
  })
  window.qiankunActions.onGlobalStateChange((state, prev) => {
    console.log(state, '父层')
    console.log('父层state变化', state)
    bookName.value = state.bookName
    bookId.value = state.bookId
    state.gotoPage
    window.qiankunState = state
  })
  // 定义父层方法
  console.log(window.qiankunActions)
  window.qiankunActions.setGlobalState({
    state: 1, // 加载子应用
    windowSelection: (data) => {
      // 绑定子应用选择监听事件
      console.log(data, '子应用选择')
      getSelection(data)
    },
    catalogChange: (data) => {
      activeCatalog.value = data.showCatalogList
      getSignData()
      console.log(data, '章节切换:目前显示的三个章节')
    },
    pageChange: (data) => {
      // {
      //   page: 100,
      //   catalog: 5,
      //   catalogId: "",
      //   catalogName: "",
      // }
      console.log(data, '页面切换:目前显示页面和对应的章节信息')
    }
  })
  // 调用子层方法
  // if (window.qiankunState && window.qiankunState.aa) window.qiankunState.aa(1)
})
watch(
@@ -989,10 +1013,10 @@
watch(
  () => bookId.value,
  (val) => {
    getNotesList() // 获取笔记
    getlineHeightList() //获取高亮
    getScribeList() //获取划线
    getScreenshotList() //截图
    // getNotesList() // 获取笔记
    // getlineHeightList() //获取高亮
    // getScribeList() //获取划线
    // getScreenshotList() //截图
  }
)
//获取目录
@@ -1631,14 +1655,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: [] //笔记
@@ -1647,21 +1670,22 @@
///内容选中
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, '子应用滚动')
    }
  })
  // window.qiankunActions.setGlobalState({
  //   gotoPage: (t, s) => {
  //     // 绑定子应用选择监听事件
  //     console.log(t, s, '子应用滚动')
  //   }
  // })
  showToolBox.value = false
  lineDelete.showLineDelete = false
  // let scroll = e.target.scrollTop
@@ -1835,67 +1859,133 @@
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 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
  }
  request({
    url: '/identity/api/ApiAppUserSetKey',
    method: 'post',
    data: {
      setKeyRequests: [
        {
          domain: dom,
          key: dialogToolData.chapter,
          value: JSON.stringify(data)
        }
      ]
    }
  }).then((res) => {
    showToolBox.value = false
    colorActive.value = ''
    toolActive.value = ''
    getSignData()
  })
}
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 lock = ref(false)
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)
        }
      }
    }
  })
  request({
    url: '/identity/api/ApiGetAppUserKey',
    method: 'post',
    data: {
      domain: 'underline-' + 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.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)
        }
      }
    }
  })
}
const addNote = () => {
  const obj = {
    desc: formData.desc
@@ -2165,7 +2255,7 @@
}
const jumpContent = (id) => {
  document.getElementById(id).scrollIntoView()
  if (window.qiankunState && window.qiankunState.gotoPage) window.qiankunState.gotoPage(5, 100)
}
const update = (item, type) => {
@@ -2680,9 +2770,7 @@
            margin: 10px 10px 10px 15px;
            border-radius: 3px;
            padding: 2px 5px;
            // opacity: 0.1;
            .con {
              all: initial;
              max-height: 65px;
              display: -webkit-box;
              -webkit-box-orient: vertical;
@@ -2772,14 +2860,17 @@
      }
      .pageBox-content {
        height: calc(100% - 57px);
        overflow-y: auto;
        background: #fbf9f4;
        .content-box {
          height: 100%;
          position: relative;
        }
        #container {
          background: #fbf9f4;
          // height: 100%;
          #container {
            background: #fbf9f4;
            height: 100%;
            #__qiankun_microapp_wrapper_for_app_content__ {
              height: 100%;
            }
          }
        }
        .canvas-box {
          height: 100%;