排队支付小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
5.9 KiB

  1. var Promise = require('../utils/lib/es6-promise.min.js');
  2. module.exports={
  3. toast(params) {
  4. if (!wx.showToast) return;
  5. if (Object.prototype.toString.call(params) != '[object Object]') {
  6. params = {
  7. title: params + ''
  8. };
  9. }
  10. var defaultParams = {
  11. duration: 1500,
  12. mask: false
  13. }
  14. wx.showToast(Object.assign(defaultParams, params || {}));
  15. },
  16. loading(params) {
  17. if (!wx.hideLoading || !wx.showLoading) return;
  18. if (!params) {
  19. wx.hideLoading();
  20. return;
  21. } else if (Object.prototype.toString.call(params) != '[object Object]') {
  22. params = { title: params + '' };
  23. }
  24. var defaultParams = {
  25. mask: true
  26. }
  27. wx.showLoading(Object.assign(defaultParams, params || {}));
  28. },
  29. confirm(params) {
  30. if (!wx.showModal) return;
  31. return new Promise((resolve, reject)=>{
  32. wx.showModal({
  33. title: params.title || '提示',
  34. content: params.content || '',
  35. showCancel: true,
  36. cancelText: params.cancelText || '取消',
  37. confirmText: params.confirmText || '确定',
  38. success(res) {
  39. resolve(res);
  40. }
  41. });
  42. });
  43. },
  44. alert(params) {
  45. if (!wx.showModal) return;
  46. if (Object.prototype.toString.call(params) != '[object Object]') {
  47. params = { content: params + '' };
  48. }
  49. var defaultParams = {
  50. textAlign: 'center',
  51. title: params.title || '提示',
  52. content: params.content || '',
  53. showCancel: false,
  54. success: params.success||function(){}
  55. }
  56. wx.showModal(defaultParams);
  57. },
  58. location(url) {
  59. console.log('location');
  60. if (!wx.navigateTo) return;
  61. wx.navigateTo({
  62. url: url
  63. });
  64. },
  65. locationReplace(url) {
  66. if (wx.reLaunch) {
  67. wx.reLaunch({
  68. url: url
  69. })
  70. } else {
  71. this.location(url);
  72. }
  73. },
  74. redirectTo(url){
  75. if ( wx.redirectTo ){
  76. wx.redirectTo({
  77. url: url
  78. })
  79. } else {
  80. this.location(url);
  81. }
  82. },
  83. /*
  84. obj : 配置信息
  85. sync: 是否同步
  86. */
  87. setStorage(obj, sync) {
  88. if (!wx.setStorageSync || !wx.setStorage) return;
  89. if (sync) {
  90. wx.setStorageSync(obj.key, obj.data);
  91. } else {
  92. wx.setStorage(obj);
  93. }
  94. },
  95. /*
  96. key : key/配置信息
  97. sync: 是否同步
  98. */
  99. getStorage(key, sync) {
  100. if (!wx.getStorageSync || !wx.getStorage) return;
  101. if (sync) {
  102. return wx.getStorageSync(key);
  103. } else {
  104. return wx.getStorage(key);
  105. }
  106. },
  107. /*
  108. key : key/配置信息
  109. sync: 是否同步
  110. */
  111. removeStorage(obj, sync) {
  112. if (!wx.removeStorageSync || !wx.removeStorage) return;
  113. if (sync) {
  114. return wx.removeStorageSync(obj.key);
  115. } else {
  116. return wx.removeStorage(obj);
  117. }
  118. },
  119. wxLogin() {
  120. return new Promise((resolve, reject) => {
  121. wx.login({
  122. success(dt) {
  123. resolve(dt);
  124. },
  125. fail(dt) {
  126. resolve(dt);
  127. },
  128. complete( res ){
  129. }
  130. });
  131. });
  132. },
  133. getUserInfo(cb) {
  134. var that = this;
  135. if (!wx.getUserInfo) return;
  136. wx.getUserInfo({
  137. success(res) {
  138. //that.globalData.userInfo = res.userInfo;
  139. //that.globalData.iv = res.iv;
  140. //that.globalData.encryptedData = res.encryptedData;
  141. typeof cb == "function" && cb(Object.assign({ iv: res.iv, encryptedData: res.encryptedData }, that.globalData.config))
  142. },
  143. fail(dt) {
  144. typeof cb == "function" && cb({ statusCode: -404 })
  145. }
  146. })
  147. },
  148. getSystemInfo() {
  149. if (!wx.getSystemInfo) return;
  150. return new Promise((resolve, reject) => {
  151. if (!wx.getSystemInfo) {
  152. reject();
  153. return;
  154. }
  155. wx.getSystemInfo({
  156. success(res) {
  157. resolve(res);
  158. },
  159. fail(res) {
  160. reject(res);
  161. }
  162. })
  163. })
  164. },
  165. getWeRunData(){
  166. return new Promise(( resolve, reject)=>{
  167. if (!wx.getWeRunData){
  168. resolve({})
  169. return;
  170. }
  171. wx.getWeRunData({
  172. success( res ){
  173. resolve( res );
  174. },
  175. fail( res ){
  176. resolve( res );
  177. }
  178. });
  179. })
  180. },
  181. chooseImage(count = 1) {//选择图片
  182. return new Promise((resolve, reject) => {
  183. wx.chooseImage({
  184. count,
  185. sizeType: ['original', 'compressed'],
  186. sourceType: ['camera','album'],
  187. success(res) {
  188. resolve(res);
  189. },
  190. fail(res) {
  191. reject(res);
  192. }
  193. })
  194. })
  195. },
  196. getFileInfo(filePath){
  197. var ctx = this;
  198. return new Promise((resolve, reject) => {
  199. wx.getFileInfo({
  200. filePath,
  201. complete( res ){
  202. res.errMsg == 'getFileInfo:ok' ? resolve(res) : reject(res);
  203. }
  204. })
  205. })
  206. },
  207. getNetworkType(){
  208. return new Promise((resolve, reject) => {
  209. wx.getNetworkType({
  210. complete(res) {
  211. resolve(res);
  212. }
  213. })
  214. })
  215. },
  216. downloadFile( url ){
  217. return new Promise((resolve, reject) => {
  218. wx.downloadFile({
  219. url,
  220. success(res) {
  221. resolve(res);
  222. },
  223. fail(res) {
  224. reject(res);
  225. }
  226. })
  227. })
  228. },
  229. navigateBack(delta=1){
  230. if (wx.navigateBack){
  231. wx.navigateBack({ delta });
  232. }
  233. },
  234. setKeepScreenOn(keepScreenOn=true){
  235. if (wx.setKeepScreenOn) {
  236. wx.setKeepScreenOn({
  237. keepScreenOn
  238. })
  239. }
  240. },
  241. getSetting(){
  242. return new Promise((resolve, reject) => {
  243. if(!wx.getSetting){
  244. setTimeout(function(){
  245. resolve({})
  246. },20);
  247. return;
  248. }
  249. wx.getSetting({
  250. success(res) {
  251. resolve(res.authSetting);
  252. },
  253. fail(res) {
  254. resolve({});
  255. }
  256. })
  257. })
  258. },
  259. openSetting(){
  260. return new Promise((resolve,reject)=>{
  261. if (!wx.openSetting){
  262. setTimeout(function () {
  263. resolve({ 'errorMsg':'wx.openSetting不支持'})
  264. }, 20);
  265. return;
  266. }
  267. wx.openSetting({
  268. complete( res ){
  269. resolve( res )
  270. }
  271. })
  272. });
  273. }
  274. }