core.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. function onAccelerometerChange() {
  2. wx.onAccelerometerChange(function(res) {
  3. console.log(res.x)
  4. console.log(res.y)
  5. console.log(res.z)
  6. this.output(["","",'x:'+res.x,'y:'+res.y,'z:'+res.z],true);
  7. })
  8. }
  9. function showToast() {
  10. wx.showToast({
  11. title: '加载中',//String 提示的内容
  12. icon: 'loading',//图标,只支持"success"、"loading"
  13. duration: 1000,//提示的延迟时间,单位毫秒,默认:1500, 最大为10000
  14. success:function(e){
  15. //接口调用成功的回调函数
  16. },
  17. fail:function(e){
  18. //接口调用失败的回调函数
  19. },
  20. complete:function(e){
  21. //接口调用结束的回调函数(调用成功、失败都会执行)
  22. }
  23. })
  24. }
  25. function showModal() {
  26. wx.showModal({
  27. title: '提示',//String 提示的标题
  28. content: '这是一个模态弹窗',//String 提示的内容
  29. showCancel:true,//是否显示取消按钮,默认为 true
  30. cancelText:'取消按钮',//String 取消按钮的文字,默认为"取消"
  31. cancelColor:'#E64340', //HexColor 取消按钮的文字颜色,默认为"#000000"
  32. confirmText:'确定按钮',//String 确定按钮的文字,默认为"确定"
  33. confirmColor:'#1AAD19', //HexColor 确定按钮的文字颜色,默认为"#3CC51F"
  34. success: function(res) {
  35. //接口调用成功的回调函数,返回res.confirm==1时,表示用户点击确定按钮
  36. if (res.confirm) {
  37. console.log('用户点击确定')
  38. }else{
  39. console.log('用户点击取消')
  40. }
  41. },
  42. fail:function(e){
  43. //接口调用失败的回调函数
  44. },
  45. complete:function(e){
  46. //接口调用结束的回调函数(调用成功、失败都会执行)
  47. }
  48. })
  49. }
  50. function showActionSheet() {
  51. wx.showActionSheet({
  52. itemList: ['一', '二', '三','四','五','六'],//String Array 按钮的文字数组,数组长度最大为6个
  53. itemColor:'#1AAD19',//HexColor 按钮的文字颜色,默认为"#000000"
  54. success: function(res) {
  55. if (!res.cancel) {
  56. console.log(res.tapIndex)
  57. }
  58. },
  59. fail:function(e){
  60. //接口调用失败的回调函数
  61. },
  62. complete:function(e){
  63. //接口调用结束的回调函数(调用成功、失败都会执行)
  64. }
  65. })
  66. }
  67. function demo() {
  68. }
  69. module.exports = {
  70. onAccelerometerChange:onAccelerometerChange,
  71. showToast:showToast,
  72. showModal:showModal,
  73. showActionSheet:showActionSheet,
  74. }