前端hook项目pc总结笔记-postgrest方法拼接扩展

http://xxxxxx/search_manufacture_cutting?manufacture_id=eq.167&is_delete=eq.0
&institution_id=eq.1
&materiel_id=eq.2482

    getOne: (resource: any, params: any,data?:any) => {
            console.log(data,params,"paramsparamsparams")
            // var test=data
            const key: any = Object.keys(params)
            // params.institution_id=``
            const id = params[key[0]];
            const primaryKey = getPrimaryKey(resource, primaryKeys);
            const query = getQuery(primaryKey, id, resource);
            //转换id
            var url = `${PostgrestUrl}/${resource}?
${query.replace("id", key[0])}&is_delete=eq.0&institution_id=eq.
${localStorage.getItem("instId")}`;
            if(data!=null&&data!=undefined&&data!=''){
                url+=`&materiel_id=eq.${data}`
            }
            return httpClient(url, {
                headers: new Headers({}),
            }).then(({ json }) => ({
                data: dataWithId(json, primaryKey),
            })).catch((err) => {
                return err
            })
        },

posted @ 2023-03-03 09:18  前端导师歌谣  阅读(17)  评论(0)    收藏  举报  来源