「云之家个性化开发」给知识目录控件赋值

140 阅读1分钟

怎么调用云之家的开放接口,并且获取知识目录,筛选出自己想要的目录给知识目录控件赋值

<script>
    cf.ready(() => {
        //获取token的函数
        async function getAccessToken () {
            let timestamp = new Date().getTime();
            let tokenJson = {
                "eid": "123456",
                "secret": "ejy000000000000000000000000D",
                "timestamp": timestamp,   //13位时间戳
                "scope": "resGroupSecret"
            }
            let response = await cf.request({
                url: 'https://www.yunzhijia.com/gateway/oauth2/token/getAccessToken',
                method: 'POST',
                data: tokenJson,
                header: {
                    'Content-type': 'application/json; charset=utf-8'
                }
            })
            console.log("===============请求getToken结束==================")
            return response.data.accessToken
        }

        cf.ready(function () {
            //预加载根目录
            var dirList = []
            // 准备一个知识目录控件的值
            var mulu = {
                "id": "668d1ed430000008e31bc314",
                "catalogId": "668d1ed000000e038e31bc314",
                "preCatalogId": null,
                "preCatalogName": null,
                "catalogName": "发文",
                "catalogCode": "FW",
                "catalogOrder": 3,
                "commentSwitch": 0,
                "downloadZip": 0,
                "zipPrint": 0,
                "contentDownload": 0,
                "contentPrint": 0,
                "enableShare": null,
                "watermarkSwitch": 0,
                "allPreCatalog": null,
                "dateRole": null,
                "restCycle": null,
                "codeNumb": null,
                "codePreview": null,
                "nextCatalogCount": 0,
                "documentCount": 0,
                "catalogCreator": "",
                "createDate": 0,
                "preCatalogCodes": null,
                "hasPermission": 1,
                "catalogManage": 1,
                "catalogManageEnableChild": 0,
                "documentManage": 1,
                "catalogView": 1,
                "fullCatalogName": null,
                "bulletinCatalog": false,
                "toutiaohaoCatalog": false,
                "allowShowCode": null,
                "allowShowCreator": null,
                "allowShowOrg": null,
                "allowShowCreateTime": null,
                "allowShowDirectory": null,
                "pubAccKey": "",
                "pubAccSecret": "",
                "pubAccName": "",
                "approvalStream": null,
                "autoCover": 0,
                "global": false,
                "genManuallyCode": false,
                "buList": null,
                "buId": "",
                "enableCopy": 0,
                "showReadStatus": 3,
                "fullPath": "沈阳西游取经有限公司/发文"
            }
            //预加载根目录 token
            getAccessToken().then((accessToken) => {
                cf.request({
                    url: `https://www.yunzhijia.com/gateway/api/yzj-info/directory/mng/getDirListByIdForGateway?accessToken=${accessToken}`,
                    method: 'GET'
                }).then((res) => {
                    console.log("================获取根目录===========================")
                    dirList = res.data
                }).catch((err) => {
                    console.log(err)
                })
            })
            //监听部门控件改变(当机构改变时,获取目录)
            cf.form.subscribeFieldValueChange("Ds_0", function (value) {
                getAccessToken().then((accessToken) => {
                    // 从目录中找到机构对应的目录
                    let findValue = dirList.find(wa => wa.catalogName == value[0].name)
                    console.log(findValue)
                    //获取子目录
                    cf.request({
                        url: "https://www.yunzhijia.com/gateway/api/yzj-info/directory/mng/getDirListByIdForGateway?" +
                            `accessToken=${accessToken}&id=${findValue.id}`,
                        method: 'GET'
                    }).then((res) => {
                        console.log("==================获取子目录==========================")
                        let dirList2 = res.data
                        // 从目录中找到发文目录
                        let findValue = dirList2.find(wa => wa.catalogName == "发文")
                        console.log(findValue)

                        // 修改之前准备的目录对象中的值,来生成新的知识目录值
                        mulu.id = findValue.id
                        mulu.catalogId = findValue.id
                        mulu.catalogName = findValue.catalogName
                        mulu.catalogCode = findValue.catalogCode
                        mulu.catalogOrder = findValue.catalogOrder
                        mulu.fullPath = `${findValue.preCatalogName}/${findValue.catalogName}`
                        // 给知识目录控件赋值
                        cf.form.setFieldValue("Cw_0", mulu)
                    }).catch((err) => {
                        console.log(err)
                    })
                })
            })
        })
    })
</script>


欢迎关注我的个人公众号「「小枫学幽默」」一起成长,一起分享生活!!

扫码关注我.png