litian
2024-05-15 7b8f96254b90c8d9cb01092e8d6ab7263972fee1
hebing
4个文件已修改
257 ■■■■ 已修改文件
src/assets/js/toolClass.ts 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/child.ts 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/qiankunState/state.ts 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/home.vue 217 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/js/toolClass.ts
@@ -12,6 +12,37 @@
  return fileSizeMsg
}
export function uuid(len = 32, radix = 16) {
  const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
  let uuid = [],
    i;
  radix = radix || chars.length;
  if (len) {
    // Compact form
    for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
  } else {
    // rfc4122, version 4 form
    let r;
    // rfc4122 requires these characters
    uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
    uuid[14] = '4';
    // Fill in random data.  At i==19 set the high bits of clock sequence as
    // per rfc4122, sec. 4.1.5
    for (i = 0; i < 36; i++) {
      if (!uuid[i]) {
        r = 0 | (Math.random() * 16);
        uuid[i] = chars[i === 19 ? (r & 0x3) | 0x8 : r];
      }
    }
  }
  return uuid.join('');
}
export default {
  getFileSize
  getFileSize,
  uuid
}
src/child.ts
@@ -14,14 +14,14 @@
    // - 必选,微应用的名称,微应用之间必须确保唯一
    name: 'app-content',
    // - 必选,微应用的入口
    entry: '//182.92.203.7:3007/books/book/1/?t=14',
    entry: '//182.92.203.7:3007/books/book/1/',
    // entry: '//192.168.3.203:8080',
    // - 必选,微应用的容器节点的选择器或者 Element 实例
    container: '#container',
    // - 必选,微应用的激活规则
    //支持直接配置字符串或字符串数组,如 activeRule: '/app1' 或 activeRule: ['/app1', '/app2'],当配置为字符串时会直接跟 url 中的路径部分做前缀匹配,匹配成功表明当前应用会被激活。
    //支持配置一个 active function 函数或一组 active function。函数会传入当前 location 作为参数,函数返回 true 时表明当前微应用会被激活。如 location => location.pathname.startsWith('/app1')。
    activeRule: '/home', //匹配所有以/subPath开头的为子应用
    activeRule: '/home' //匹配所有以/subPath开头的为子应用
    //loader - (loading: boolean) => void - 可选,loading 状态发生变化时会调用的方法。
  }
}
src/qiankunState/state.ts
@@ -4,7 +4,8 @@
  bookId:0,
  windowSelection: null,
  showCatalogList:[],
  gotoPage:null
  gotoPage:null,
  renderSign: null
}
src/views/home.vue
@@ -321,7 +321,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>
@@ -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) => {
@@ -981,6 +986,8 @@
      getSelection(data)
    },
    catalogChange: (data) => {
      activeCatalog.value = data.showCatalogList
      getSignData()
      console.log(data, '章节切换:目前显示的三个章节')
    },
    pageChange: (data) => {
@@ -1011,10 +1018,10 @@
watch(
  () => bookId.value,
  (val) => {
    getNotesList() // 获取笔记
    getlineHeightList() //获取高亮
    getScribeList() //获取划线
    getScreenshotList() //截图
    // getNotesList() // 获取笔记
    // getlineHeightList() //获取高亮
    // getScribeList() //获取划线
    // getScreenshotList() //截图
  }
)
//获取目录
@@ -1693,14 +1700,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,11 +1715,12 @@
///内容选中
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
  }
}
@@ -1897,67 +1904,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