| | |
| | | }, |
| | | |
| | | // 扁平化数据转换tree |
| | | getTreeList(rootList, pathLength, newArr, path) { |
| | | getTreeList(rootList, newArr, path) { |
| | | for (const item of rootList) { |
| | | if ((pathLength - item.productLinkPath.length >= 0 && pathLength - item.productLinkPath.length <= 3) && item.productLinkPath.includes(path)) { |
| | | if (path == item.productLinkPath.replace('\\' + item.id, '')) { |
| | | if (item.sysType == 'CmsItem') { |
| | | if (item.selectType == 'webpage') { |
| | | item.disabled = true |
| | |
| | | if (item.fileMap[item.file].protectType == 'Private') item.disabled = true |
| | | } |
| | | } |
| | | // newArr.push(item) |
| | | // 在插入过程中对数据进行排序 并且去除已经领取和购买的 |
| | | if (item.sysType == 'CmsFolder') { |
| | | newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item) |
| | |
| | | //给数组里面再添加一个children的空数组 |
| | | for (const i of newArr) { |
| | | i.children = [] |
| | | this.getTreeList(rootList, pathLength + 6, i.children, i.productLinkPath) |
| | | this.getTreeList(rootList, i.children, i.productLinkPath) |
| | | if (i.children.length == 0) { |
| | | delete i.children |
| | | } |
| | |
| | | // 排序数组 按照productLinkPath |
| | | insertAndSortObjectsByProductLinkPath(array, newObj) { |
| | | // 查找新对象应该插入的位置 |
| | | let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.length - 6, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.length - 6, obj.productLinkPath.length))); |
| | | |
| | | let insertIndex = array.findIndex(obj => newObj.id < obj.id); |
| | | // 如果没有找到合适的位置,则放在数组末尾 |
| | | if (insertIndex === -1) { |
| | | insertIndex = array.length; |
| | |
| | | // 测试6 正式5 |
| | | // 对数组进行排序 |
| | | array.sort((a, b) => { |
| | | if (Number(a.productLinkPath.substring(a.productLinkPath.length - 5, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.length - 5, b.productLinkPath.length))) { |
| | | return -1; |
| | | } |
| | | if (Number(a.productLinkPath.substring(a.productLinkPath.length - 5, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.length - 5, b.productLinkPath.length))) { |
| | | return 1; |
| | | } |
| | | // a must be equal to b |
| | | if (a.id < b.id) return -1; |
| | | if (a.id > b.id) return 1; |
| | | return 0; |
| | | }); |
| | | |
| | | // 返回更新后的数组 |
| | | return array; |
| | | }, |
| | |
| | | if (type.value == item.resourcesClassification) |
| | | item.resourceClass = type.name; |
| | | }); |
| | | if (this.data.tabValue == "jsek_teachingResources") {} else if (this.data.tabValue == "jsek_cloudLearning") { |
| | | item.isbuy = this.isShowNeedBuy(item); |
| | | item.isShopCar = this.isShoppingCart(item); |
| | | } |
| | | item.isbuy = this.isShowNeedBuy(item); |
| | | item.isShopCar = this.isShoppingCart(item); |
| | | } |
| | | }); |
| | | // 显示 需要购买的和需要免费领取的 |
| | | // const arr = res.datas.cmsDatas[0].datas.filter(item => this.resourceIsBuy(item)) |
| | | // if (!arr.length) { |
| | | // return this.setData({ |
| | | // loading: false, |
| | | // haider: true, |
| | | // noData: true |
| | | // }) |
| | | // } |
| | | const num = query.cmsPath.length + 6 |
| | | this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\') |
| | | this.getTreeList(res.datas.cmsDatas[0].datas, list, query.cmsPath) |
| | | list = this.ensureTreeConsistency(list) |
| | | list = this.changeResourceChildren(list) |
| | | console.log('修改后云', list); |
| | |
| | | }) |
| | | }, |
| | | |
| | | // 获取教学资源 云学习 云测试 |
| | | getResourceData(type) { |
| | | this.setData({ |
| | | loading: true, |
| | | noResources: false, |
| | | }); |
| | | let query = { |
| | | path: "*", |
| | | queryType: "*", |
| | | productId: this.data.bookId, |
| | | cmsPath: type.productLinkPath, |
| | | itemFields: { |
| | | SysType: "CmsFolder", |
| | | // 资源类型,试读文件,是否允许下载等参数 |
| | | selectType: [], |
| | | freeFile: [], |
| | | file: [], |
| | | resourcesClassification: [], |
| | | isDownload: [], |
| | | jsek_resourceBrief: [], |
| | | jsek_link: [], |
| | | jsek_questionBank: [], |
| | | }, |
| | | pading: { |
| | | start: 0, |
| | | size: 999, |
| | | }, |
| | | }; |
| | | app.MG.store |
| | | .getProductDetail(query) |
| | | .then(async (res) => { |
| | | if (!res.datas.cmsDatas[0].datas.length) { |
| | | return this.setData({ |
| | | noResources: true, |
| | | loading: false, |
| | | }); |
| | | } |
| | | //教学资源 云学习 |
| | | if ( |
| | | type.refCode == "jsek_teachingResources" || |
| | | type.refCode == "jsek_cloudLearning" |
| | | ) { |
| | | if (res.datas.cmsDatas[0].datas.length > 0) { |
| | | res.datas.cmsDatas[0].datas.forEach((item) => { |
| | | (item.checked = false), (item.checkAll = true); |
| | | }); |
| | | const list = await this.getAllResource(res.datas.cmsDatas[0].datas); |
| | | if (type.refCode == "jsek_teachingResources") { |
| | | this.setData({ |
| | | teach: list, |
| | | loading: false, |
| | | }); |
| | | this.findChildIds(this.data.teach, (this.data.openTeachids = [])); |
| | | } else if (type.refCode == "jsek_cloudLearning") { |
| | | const result = []; |
| | | res.datas.cmsDatas[0].datas.forEach((item) => { |
| | | item.checked = false; |
| | | }); |
| | | this.findChildIds(list, result); |
| | | this.setData({ |
| | | learn: list, |
| | | loading: false, |
| | | openLearnids: result, |
| | | }); |
| | | } |
| | | console.log(list, '云學習'); |
| | | } else { |
| | | // 无数据 |
| | | } |
| | | } else if (type.refCode == "jsek_questionBank") { |
| | | // const list = await this.getAllResource(res.datas.cmsDatas[0].datas) |
| | | this.setData({ |
| | | test: res.datas.cmsDatas[0].datas, |
| | | loading: false, |
| | | }); |
| | | } else { |
| | | console.log("其他"); |
| | | } |
| | | }) |
| | | .catch((e) => { |
| | | console.log(e); |
| | | }); |
| | | }, |
| | | // 获取tag下所有资源 |
| | | async getAllResource(data) { |
| | | if (!data.length) return false; |
| | | for (let i = 0; i < data.length; i++) { |
| | | let item = data[i]; |
| | | if (item.sysType == "CmsFolder" && item.childrenCount > 0) { |
| | | item.children = []; |
| | | item.children = await this.getFolderItem(item.productLinkPath); |
| | | await this.getAllResource(item.children); |
| | | } |
| | | } |
| | | return data; |
| | | }, |
| | | // 获取资源接口 |
| | | async getFolderItem(path) { |
| | | let query = { |
| | | path: "*", |
| | | queryType: "*", |
| | | productId: this.data.bookId, |
| | | cmsPath: path, |
| | | itemFields: { |
| | | SysType: "CmsFolder", |
| | | // 资源类型,试读文件,是否允许下载等参数 |
| | | selectType: [], |
| | | freeFile: [], |
| | | file: [], |
| | | protectedFile: [], |
| | | resourcesClassification: [], |
| | | isDownload: [], |
| | | jsek_resourceBrief: [], |
| | | jsek_link: [], |
| | | accessType: [], |
| | | learnSelectType: [], |
| | | }, |
| | | pading: { |
| | | start: 0, |
| | | size: 999, |
| | | }, |
| | | }; |
| | | const data = await app.MG.store.getProductDetail(query); |
| | | data.datas.cmsDatas[0].datas.forEach((item) => { |
| | | this.data.resourceClassList.forEach((type) => { |
| | | if (type.value == item.resourcesClassification) |
| | | item.resourceClass = type.name; |
| | | }); |
| | | // 网页 不能下载 私有文件 |
| | | if (item.sysType == "CmsItem") { |
| | | if (item.selectType == "webpage") { |
| | | item.disabled = true; |
| | | } else { |
| | | if (item.isDownload != 1) { |
| | | item.disabled = true; |
| | | } |
| | | } |
| | | if (item.file) { |
| | | if (item.fileMap[item.file].protectType == "Private") |
| | | item.disabled = true; |
| | | } |
| | | } |
| | | }); |
| | | data.datas.cmsDatas[0].datas.forEach((item) => { |
| | | item.checked = false; |
| | | item.isbuy = this.isShowNeedBuy(item); |
| | | item.isShopCar = this.isShoppingCart(item); |
| | | }); |
| | | return data.datas.cmsDatas[0].datas; |
| | | }, |
| | | async getBookInfo(id) { |
| | | this.setData({ |
| | | "mockData'.id": 0, |
| | |
| | | bookDetail: res.datas, |
| | | buyIdList: res.datas.purchasedSaleMethodIdList, |
| | | }); |
| | | // this.getResourceData({ |
| | | // productLinkPath: this.data.productLinkPath, |
| | | // refCode: this.data.refCode, |
| | | // }); |
| | | // this.getResourceCode( |
| | | // res.datas.id, |
| | | // res.datas.rootCmsItemId |
| | | // ) |
| | | this.getResourceDataList({ |
| | | productLinkPath: this.data.productLinkPath, |
| | | refCode: this.data.refCode, |
| | | }) |
| | | }); |
| | | |
| | | }, |
| | | getResourceCode(bookId, cmsId) { |
| | | let query = { |
| | | path: '*', |
| | | queryType: '*', |
| | | productId: bookId, |
| | | cmsPath: cmsId, |
| | | itemFields: { |
| | | SysType: 'Cms' |
| | | }, |
| | | pading: { |
| | | start: 99, |
| | | size: 0 |
| | | } |
| | | } |
| | | app.MG.store.getProductDetail(query).then(res => { |
| | | console.log('图书资源', res.datas.cmsDatas[0].datas); |
| | | }) |
| | | }, |
| | | // 获取已购买商品 |
| | | getShoppingCartProductGet() { |