/*
 * @Author: tengmingxue 1473375109@qq.com
 * @Date: 2023-08-15 11:20:48
 * @LastEditors: tengmingxue 1473375109@qq.com
 * @LastEditTime: 2023-09-25 17:47:03
 * @FilePath: \xld-gis-admin\src\api\resource\scene.ts
 * @Description: 文件资源接口
 */
import { defHttp } from '/@/utils/http/axios';
import { session } from "/@/utils/Memory.js";
enum Api {
    Login = '/callProvider',
    UploadFiles = '/datastore/file/uploadFile/1fcf0fc166206ceb7f2780302ec8f854',
    Download = '/datastore/file/download'
}
const interfaceType = { apiUrl2: true };

/**
 * @description:获取地图资源列表
 */
export function list() {
    const formData = new FormData();
    formData.append("interfaceName", "antu.space.provider.sservicebase.ServiceBaseMetaDataViewProvider");
    formData.append("methodName", "getResourcePagedList");
    formData.append("args[]", session.getItem('tokenV2'));
    formData.append("args[]", `{"type":"DR","pageIndex":1,"pageSize":20,"orderBy":"updatedate DESC"}`);
    // // formData.append("args[]", `{"type":"DR","pageIndex":1,"userid": "${session.getItem('userId')}","pageSize":20}`);
    // formData.append("args[]", `{"type":"DR","pageIndex":1,"pageSize":20,"userid": "${session.getItem('userId')}"}`);
    // // formData.append("args[]", `{"type":"DR","pageIndex":1,"pageSize":20}`);
    // // formData.append("args[]", `{"type":"DR","pageIndex":1,"pageSize":20,"orderBy":"updatedate DESC"}`);
    // //"userid": "${session.getItem('userId')}",
    return new Promise<void>((resolve, reject) => {
        defHttp.post({ url: Api.Login, params: formData, ...interfaceType })
            .then((r) => {
                let result = r.result === '' ? [] : JSON.parse(r.result)
                console.log("文件资源上传列表:", result)
                resolve(result);
            })
    })
}

/**
 * 查询资源列表
*/
export function listPage(param) {
    const data = JSON.stringify(param)
    const formData = new FormData();
    formData.append("interfaceName", "antu.space.provider.sservicebase.ServiceBaseMetaDataViewProvider");
    formData.append("methodName", "getResourcePagedList");
    formData.append("args[]", session.getItem('tokenV2'));
    formData.append("args[]", data);    //'{"type":"DR","pageIndex":1,"pageSize":20,"orderBy":"updatedate DESC"}'
    return new Promise<void>((resolve, reject) => {
        defHttp.post({ url: Api.Login, params: formData, ...interfaceType })
            .then((r) => {
                let result = r.result === '' ? {} : JSON.parse(r.result)
                resolve(result);
            })
    })
}


/**
 * @description:文件资源下载
 * @param:id         文件id
 * @param:userid     用户id
 * @param:parentId   文件夹id      
 */
export function getFileUrl(param) {
    return new Promise<void>((resolve, reject) => {
        try {
            defHttp.post({
                url: Api.Download,
                params: {
                    objs: [{ id: param.id, objType: "FILE", userId: param.userid }],
                    parentId: param.parentId
                },
            })
                .then((r) => {
                    if (r && r.resp_code == 0 && r.resp_msg == "OK") {
                        resolve(r.datas[0]);
                    } else {
                        resolve()
                    }
                }).catch(e => {
                    resolve()
                })
        } catch (error) {
            resolve()
        }
    })
}


/**
 * 通过id获取版本管理数据
*/
export function getVersion(id) {
    const formData = new FormData();
    formData.append("interfaceName", "antu.space.provider.sdataversion.SDataVersionProvider");
    formData.append("methodName", "getDetailById");
    formData.append("args[]", session.getItem('tokenV2'));
    formData.append("args[]", id);
    return new Promise<void>((resolve, reject) => {
        defHttp.post({ url: Api.Login, params: formData, ...interfaceType })
            .then((r) => {
                let result = r.result === '' ? {} : JSON.parse(r.result)
                resolve(result);
            })
    })
}




