New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gm-utils

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gm-utils

冠美小程序前端api库

  • 3.0.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

gm-apis gm-utils 冠美-阿里小程序API函数库

介绍

冠美-阿里小程序API函数库,从 阿里小程序渐进框架 框架中分离出来,定位为函数库,封装常用方法、云函数以及工具函数。

文档查看【语雀】

安装

npm i gm-apis -s or

npm i gm-utils -s

或者小程序开发工具依赖选项卡进行安装

1

初始化

app.js文件头部你需要加这两行代码,框架就开始运作了

import gmApi from "gm-apis";
let apis = gmApi({
    env:'test'
});

示例

下面是完整的app.js文件示例

import gmApis from "gm-apis";
// import myApi from "./myApi"; //自己定义和项目具体业务相关的云函数

let apis = gmApis({//config
  env:"test",    //当前环境 test | online ,切换环境这个字段必改,
  envs:{
    //根据上面env判断对应配置,并深度合并到config
    "test":{
        //测试环境的配置
        appUrl:"https://m.duanqu.com?_ariver_appid=3000000003651171&nbsv=0.1.2004151741.2&nbsource=debug&nbsn=DEBUG",
    },
    "online":{
        //正式环境的配置
        appUrl:"https://m.duanqu.com?_ariver_appid=3000000003651171"
    }
  },
  
  //店铺配置信息 涉及入会地址
  shop:{
    shopId: "106564654",
    sellerId:"1818112088",
  },
    //涉及分享信息和相关api
  share:{
      //https://miniapp.open.taobao.com/docV3.htm?docId=118909&docType=1
      title:"",
      desc:"",
      imageUrl:"",
      // url 地址信息在会在相关函数中动态生成,所以这里不用设置
  },
  debug: false,//是否开启框架内的log调试信息 apis.util.log apis.util.warn
  isAutoLoading: true, //是否开启调云函数自动显示loading
  
  //数据库配置 影响相关函数:apis.$init apis.$save apis.$get apis.$set 等
  activityId: "",  //不配置或字符串为空 默认为 "default"
  isAutoInitICSS: true, //是否自动创建页面配置数据库表和索引 默认表名 icss 建议设置test环境下开启,online环境手动创建表和索引 或者在online环境下执行apis.ICSSInit(true);创建表格和索引
  ICSSTableName: 'icss' //页面配置数据表名
});


// apis.addAPI(myApi) //来自引入文件myApi

// apis.config 为配置信息(根据环境会自动切换)
// 云函数也会根据环境自动切换 
//apis可以放入到App配置中如:
App({
  apis,//页面和组件 可以获取  let apis = getApp().apis;
  onLaunch(options) {
  },
  onShow(options) {
  },
  //...
});

下面是完整的myApi.js文件示例(自己定义和项目具体业务相关的云函数)

export default (apis) => {
    
    const { fn, f, fetchData, fetchMessage, config, dateFormat } = apis;
    //config 为配置信息
    //console.log("apis", apis)


    let myApis = {
        async activityGet(){
            return await f("activity.activityGet", {activityId: apis.config.activityId});
        },
        //...
    };

    //在外部apis对象可以调用 apis.activityGet

    return myApis
}

调试

部分函数支持在开发者工具中调用调试

2

FAQs

Package last updated on 12 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc