/*!
* Bmob WeChat applet SDK
* http://www.bmob.cn
* Copyright Bmob, Inc.
* The Bmob WeChat applet SDK is freely distributable under the MIT license.
* (c) 2016-2050 Magic
*/
(function (root) {
var _ = require('underscore.js');
var Bmob = {};
Bmob.VERSION = "js0.0.1";
Bmob._ = _;
var EmptyConstructor = function () { };
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = Bmob;
}
exports.Bmob = Bmob;
} else {
root.Bmob = Bmob;
}
// Helper function to correctly set up the prototype chain, for subclasses.
// Similar to `goog.inherits`, but uses a hash of prototype properties and
// class properties to be extended.
var inherits = function (parent, protoProps, staticProps) {
var child;
// The constructor function for the new subclass is either defined by you
// (the "constructor" property in your `extend` definition), or defaulted
// by us to simply call the parent's constructor.
if (protoProps && protoProps.hasOwnProperty('constructor')) {
child = protoProps.constructor;
} else {
/** @ignore */
child = function () {
parent.apply(this, arguments);
};
}
// Inherit class (static) properties from parent.
Bmob._.extend(child, parent);
// Set the prototype chain to inherit from `parent`, without calling
// `parent`'s constructor function.
EmptyConstructor.prototype = parent.prototype;
child.prototype = new EmptyConstructor();
// Add prototype properties (instance properties) to the subclass,
// if supplied.
if (protoProps) {
Bmob._.extend(child.prototype, protoProps);
}
// Add static properties to the constructor function, if supplied.
if (staticProps) {
Bmob._.extend(child, staticProps);
}
// Correctly set child's `prototype.constructor`.
child.prototype.constructor = child;
// Set a convenience property in case the parent's prototype is
// needed later.
child.__super__ = parent.prototype;
return child;
};
// Set the server for Bmob to talk to.
Bmob.serverURL = "https://api.bmob.cn";
Bmob.fileURL = "http://file.bmob.cn";
// Check whether we are running in Node.js.
if (typeof (process) !== "undefined" && process.versions && process.versions.node) {
Bmob._isNode = true;
}
/**
* 初始化时需要调用这个函数。可以从bmob中获取所需的key
*
* @param {String} applicationId 你的 Application ID.
* @param {String} applicationKey 你的 restful api Key.
* @param {String} masterKey (optional) 你的 bmob Master Key.
*/
Bmob.initialize = function (applicationId, applicationKey, masterKey) {
Bmob._initialize(applicationId, applicationKey, masterKey);
};
/**
* Call this method first to set up authentication tokens for Bmob.
* This method is for Bmob's own private use.
* @param {String} applicationId Your Bmob Application ID.
* @param {String} applicationKey Your Bmob Application Key
*/
Bmob._initialize = function (applicationId, applicationKey, masterKey) {
Bmob.applicationId = applicationId;
Bmob.applicationKey = applicationKey;
Bmob.masterKey = masterKey;
Bmob._useMasterKey = true;
Bmob.serverURL = "https://" + applicationId + ".bmobcloud.com";
};
if (Bmob._isNode) {
Bmob.initialize = Bmob._initialize;
}
/**
* Returns prefix for localStorage keys used by this instance of Bmob.
* @param {String} path The relative suffix to append to it.
* null or undefined is treated as the empty string.
* @return {String} The full key name.
*/
Bmob._getBmobPath = function (path) {
if (!Bmob.applicationId) {
throw "You need to call Bmob.initialize before using Bmob.";
}
if (!path) {
path = "";
}
if (!Bmob._.isString(path)) {
throw "Tried to get a localStorage path that wasn't a String.";
}
if (path[0] === "/") {
path = path.substring(1);
}
return "Bmob/" + Bmob.applicationId + "/" + path;
};
/**
* Returns prefix for localStorage keys used by this instance of Bmob.
* @param {String} path The relative suffix to append to it.
* null or undefined is treated as the empty string.
* @return {String} The full key name.
*/
Bmob._getBmobPath = function (path) {
if (!Bmob.applicationId) {
throw "You need to call Bmob.initialize before using Bmob.";
}
if (!path) {
path = "";
}
if (!Bmob._.isString(path)) {
throw "Tried to get a localStorage path that wasn't a String.";
}
if (path[0] === "/") {
path = path.substring(1);
}
return "Bmob/" + Bmob.applicationId + "/" + path;
};
/**
* Returns the unique string for this app on this machine.
* Gets reset when localStorage is cleared.
*/
Bmob._installationId = null;
Bmob._getInstallationId = function () {
// See if it's cached in RAM.
if (Bmob._installationId) {
return Bmob._installationId;
}
// Try to get it from localStorage.
var path = Bmob._getBmobPath("installationId");
// Bmob._installationId = Bmob.localStorage.getItem(path);
wx.getStorage({
key: 'key',
success: function (res) {
Bmob._installationId = res.data;
console.log(res.data)
}
})
if (!Bmob._installationId || Bmob._installationId === "") {
// It wasn't in localStorage, so create a new one.
var hexOctet = function () {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
};
Bmob._installationId = (hexOctet() + hexOctet() + "-" + hexOctet() + "-" + hexOctet() + "-" + hexOctet() + "-" + hexOctet() + hexOctet() + hexOctet());
wx.setStorage({
key: path,
data: Bmob._installationId
})
}
return Bmob._installationId;
};
Bmob._parseDate = function (iso8601) {
var regexp = new RegExp("^([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2})" + "T" + "([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})" + "(.([0-9]+))?" + "Z$");
var match = regexp.exec(iso8601);
if (!match) {
return null;
}
var year = match[1] || 0;
var month = (match[2] || 1) - 1;
var day = match[3] || 0;
var hour = match[4] || 0;
var minute = match[5] || 0;
var second = match[6] || 0;
var milli = match[8] || 0;
return new Date(Date.UTC(year, month, day, hour, minute, second, milli));
};
Bmob._ajax = function (method, url, data, success, error) {
var options = {
success: success,
error: error
};
var promise = new Bmob.Promise();
var dataObject = JSON.parse(data);
var error;
wx.showNavigationBarLoading()
if (dataObject.category == "wechatApp") {
wx.uploadFile({
url: url,
filePath: dataObject.base64,
name: 'file',
header: {
"X-Bmob-SDK-Type": "wechatApp"
},
formData: dataObject,
success: function (res) {
没有合适的资源?快使用搜索试试~ 我知道了~
小程序轮播图+首页列表源码
共14个文件
js:7个
jpg:3个
wxss:2个
4星 · 超过85%的资源 需积分: 41 61 下载量 85 浏览量
2017-09-12
21:23:09
上传
评论 1
收藏 289KB ZIP 举报
温馨提示
零基础自学小程序系列007---小程序轮播图+首页列表源码。这是我的源码系列,更多源码讲解和源码资源可以到我的博客查看:http://blog.csdn.net/qiushi_1990
资源推荐
资源详情
资源评论
收起资源包目录
首页轮播图+列表.zip (14个子文件)
首页轮播图+列表
app.js 0B
images
aaa.jpg 105KB
bbb.jpg 77KB
ccc.jpg 43KB
data
posts-data.js 444B
utils
util.js 481B
common.js 458B
bmob.js 264KB
underscore.js 59KB
pages
index
index.wxml 832B
index.js 285B
index.wxss 368B
app.json 238B
app.wxss 18B
共 14 条
- 1
资源评论
- zjbtony2018-06-27帮我的大忙了,谢谢楼主
- 我叫大王去巡山咧2018-06-26可以,新手使用很方便
- 苦艾酒丶2018-06-07不错,不错,不错
- kakariko2018-03-26不错不错不错
编程小石头
- 粉丝: 1w+
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功