123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import wx from 'weixin-jsapi'
- let dsHost = "";
- dsHost = location.hostname;
- export const path = `${location.origin}/service`
- export function get(url, data = {}) {
- url = path + url;
- return new Promise((resolve, reject) => {
- uni.request({
- url,
- data,
- header: {
- 'Cache-Control': 'no-cache',
- 'Ds-Host': dsHost,
- },
- success(res) {
- if(res.statusCode === 200){
- resolve(res.data);
- }else{
- reject();
- uni.showToast({
- icon: 'none',
- title: '请求数据失败!'
- });
- }
- },
- fail(err) {
- reject();
- uni.showToast({
- icon: 'none',
- title: '请求数据失败!'
- });
- }
- })
- });
- }
- export function post(url, data = {}) {
- url = path + url;
- return new Promise((resolve, reject) => {
- uni.request({
- method: 'POST',
- url,
- data,
- header: {
- 'Cache-Control': 'no-cache',
- 'Ds-Host': dsHost,
- },
- success(res) {
- if(res.statusCode === 200){
- resolve(res.data);
- }else{
- reject();
- uni.showToast({
- icon: 'none',
- title: '请求数据失败!'
- });
- }
- },
- fail(err) {
- reject();
- uni.showToast({
- icon: 'none',
- title: '请求数据失败!'
- });
- }
- })
- });
- }
- export function SM(code = '') {
- if(code){
- return Promise.resolve(code);
- }
-
- return new Promise((resolve, reject) => {
- uni.scanCode({
- onlyFromCamera: true,
- success: function(res) {
- let str = res.result.replace(/[\s\/]/g, '') || 'none';
- str = str.replace(/CODABAR,/i, '');
- str = str.replace(/CODE_128,/i, '');
- resolve(str);
- },
- fail(err) {
- reject(err);
- }
- });
- });
-
-
- return new Promise((resolve, reject) => {
- let param = {
- requestUrl: location.href.split('#')[0]
- };
- post("/wechat/getJsConfig", param).then(res => {
- if (res) {
- wx.config({
- debug: false,
- appId: res.appId,
- timestamp: res.timestamp,
- nonceStr: res.nonceStr,
- signature: res.signature,
- jsApiList: res.jsApiList
- });
- wx.ready(function() {
- wx.scanQRCode({
- desc: "scanQRCode desc",
- needResult: 1,
- scanType: ["qrCode", "barCode"],
- success: function(res) {
-
- let str = res.resultStr.replace(/[\s\/]/g, '') || 'none';
- str = str.replace(/CODABAR,/i, '');
- str = str.replace(/CODE_128,/i, '');
- resolve(str);
- },
- cancel(err){
- reject(err);
- }
- });
- });
- }
- })
- });
-
- }
|