123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- import * as config from '@/config'
- import WXBizDataCrypt from './WXBizDataCrypt.js'
- let baseUrl = config.def().baseUrlNew
- // 定义基础请求路径(后端服务器地址)
- const baseRequest = (_gp, _mt, data = {}, failCallback) => {
- //异步请求数据
- return new Promise(resolve => {
- // if (!userInfo || !userInfo.accessToken) {
- // userInfo = uni.getStorageSync('userInfo')
- // }
- // let accessToken = userInfo ? userInfo.accessToken : ''
- let baseUrl = config.def().baseUrlNew
- uni.request({
- url: baseUrl + '/m.api',
- data: {
- ...data,
- _gp,
- _mt
- },
- method: 'POST',
- header: {
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
- // 'ACCESSTOKEN': accessToken
- },
- success: (res) => {
- if (res.statusCode === 200) {
- if (res.data.errno === 200) {
- resolve(res.data);
- } else {
- if (failCallback) {
- failCallback(res.data)
- } else {
- uni.showToast({
- title: res.data.errmsg,
- icon: 'none'
- })
- }
- }
- }
- }
- })
- })
- }
- //带Token请求
- const TokenRequest = (method, url, data, header) => {
- var contentheader = 'application/json'
- if (header) {
- contentheader = header
- }
- let ac_token = "";
- uni.getStorage({
- key: 'userInfo',
- success: function(res) {
- ac_token = res.data.accessToken
- }
- });
- //此token是登录成功后后台返回保存在storage中的
- let DefaultOpts = {
- url: baseUrl + url,
- data: data,
- method: method,
- header: {
- 'content-type': contentheader,
- 'Token': ac_token,
- }
- }
- let promise = new Promise(function(resolve, reject) {
- uni.request(DefaultOpts).then(
- (res) => {
- console.log(JSON.stringify(res[1].data))
- if (res[1].data.code == '200' || res[1].data.code == 200) {
- // 后端返回的状态码100为成功状态,成功则返回请求结果,在app调试时可以通过console.log(JSON.stringify(res[1].data))来查看返回值(以项目实际情况为准)
- resolve(res[1].data)
- }
- if (res[1].data.code == '105' || res[1].data.code == 105) {
- // 后端返回状态码为105则为未登录状态(以项目实际情况为准)
- uni.showToast({
- icon: 'none',
- title: '尚未登录',
- duration: 2000
- });
- // 尚未登录的逻辑处理
- return false
- }
- }
- ).catch(
- (response) => {
- reject(response)
- }
- )
- })
- return promise
- }
- //微信登录
- const wxlogin = () => {
- let promise = new Promise(function(resolve, reject) {
- uni.login({
- "provider": "weixin",
- success: function(wxres) {
- console.log("wxlogin",wxres)
- baseRequest('commonUserApp', 'commonUserLogin', {
- loginType: 1,
- raw: JSON.stringify(wxres)
- }, failres => {
- uni.showToast({
- icon: "none",
- title: failres.errmsg,
- duration: 3000
- });
- uni.hideLoading()
- }).then(res => {
- resolve(res.data)
- })
- },
- fail: function(err) {
- reject(err.code)
- }
- })
- })
- return promise
- }
- //获取手机号
- const getPhone = (e, userInfo) => {
- let promise = new Promise(function(resolve, reject) {
- if (e.mp.detail.errMsg === "getPhoneNumber:ok") {
- let appId = 'wx5d8906c2208c899f'
- let sessionKey = userInfo.sessionKey
- let encryptedData = e.mp.detail.encryptedData
- let iv = e.mp.detail.iv
- let data =''
- try {
-
- console.log('解密前 encryptedData: ', encryptedData)
- console.log('解密前 iv: ', iv)
- console.log('解密前 appId: ', appId)
- console.log('解密前 sessionKey: ', sessionKey)
- data= WXBizDataCrypt.prototype.decryptData(encryptedData, iv, appId, sessionKey)
- console.log('解密后 data: ', data)
- resolve(data.phoneNumber)
- } catch (e) {
- uni.showToast({
- icon: "none",
- title: e,
- duration: 3000
- });
- }
- }
- })
- return promise
- }
- //同步信息
- const syncInfo = (userInfo) => {
- let promise = new Promise(function(resolve, reject) {
- if (!userInfo.head) userInfo.head =
- 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/card_head.png'
- if (!userInfo.nickname) {
- let code = ""
- for (var i = 0; i < 6; i++) {
- code += parseInt(Math.random() * 10);
- }
- userInfo.nickname = 'user' + code
- }
- baseRequest('commonUserApp', 'edit', {
- commonUserInfo: JSON.stringify(userInfo)
- }, failres => {
- uni.showToast({
- icon: "none",
- title: failres.errmsg,
- duration: 3000
- });
- reject(err.code)
- }).then(res => {
- resolve(res.data)
- })
- })
- return promise
- }
- // 处理海报数据
- const makeCanvasData = (check_idx,height,posterObj1,theight) => {
- console.log(height,theight)
- var dth = (theight - 22) * 2
- var h=((height+40)*2)
- console.log(posterObj1)
- var posterObj= {}
- switch (check_idx) {
- case 0:
- posterObj={
- width: '670rpx',
- height: h+'rpx',
- background: '#fff',
- borderRadius: '16rpx',
- views:[
-
- {
- type: 'text',
- text: posterObj1.title,
- use:'title',
- css: {
- fontSize: '32rpx',
- color: '#1A2033',
- fontWeight: 'bold',
- lineHeight: '45rpx',
- left: '32rpx',
- top: '410rpx',
- width: '606rpx'
- }
- },
- {
- type: 'text',
- text: posterObj1.title1,
- use:'title1',
- css: {
- fontSize: '28rpx',
- fontWeight: 'bold',
- color: '#1A2033',
- lineHeight: '28rpx',
- left: '32rpx',
- top: 535+dth+'rpx'
- }
- },
- {
- type: 'text',
- text: '扫描识别二维码',
- use:'title2',
- css: {
- fontSize: '24rpx',
- color: '#4070FF',
- lineHeight: '24rpx',
- left: '32rpx',
- top: 579+dth+'rpx'
- }
- },
- {
- type: 'image',
- src: posterObj1.image,
- use:'dt',
- css: {
- left: '32rpx',
- top: '44rpx',
- width: '606rpx',
- height: '341rpx',
- borderRadius: '16rpx'
- }
- },
- {
- type: 'image',
- src: posterObj1.qrcode,
- use:'qrcode',
- css: {
- left: '410rpx',
- top: 520+dth+'rpx',
- // transform: 'translate(-50%,0)',
- width: '240rpx',
- height: '240rpx',
- }
- },
- // {
- // type: 'text',
- // text: '———— 由云现场提供技术支持 ————',
- // css: {
- // left: '0',
- // top: '863rpx',
- // width: '100%',
- // textAlign: 'center',
- // fontSize: '24rpx',
- // color: '#989FB3',
- // lineHeight: '33rpx'
- // }
- // }
- ],
- }
- break;
- case 1:
- posterObj={
- width: '670rpx',
- height: h+'rpx',
- background: '#fff',
- borderRadius: '16rpx',
- views: [{
- type: 'image',
- use:'bg',
- src: 'https://s.yun-live.com/images/20210201/39ae4d9d8ad0b1acac7c224e845c641f.png',
- css: {
- left: '0',
- top: '0',
- width: '100%',
- height: '100%'
- }
- },
- {
- type: 'image',
- src: posterObj1.image,
- css: {
- left: '32rpx',
- top: '44rpx',
- width: '606rpx',
- height: '341rpx',
- borderRadius: '16rpx'
- }
- },
- {
- type: 'text',
- text: posterObj1.title,
- use:'title',
- css: {
- fontSize: '32rpx',
- color: '#fff',
- fontWeight: 'bold',
- lineHeight: '45rpx',
- left: '32rpx',
- top: '420rpx',
- width: '590rpx'
- }
- },
- {
- type: 'text',
- text:posterObj1.title1,
- use:'title1',
- css: {
- fontSize: '28rpx',
- fontWeight: 'bold',
- color: '#D8AB87',
- lineHeight: '28rpx',
- left: '32rpx',
- top: 535+dth+'rpx'
- }
- },
- {
- type: 'text',
- text: '扫描识别二维码',
- use:'title2',
- css: {
- fontSize: '24rpx',
- color: '#FFFFFF',
- lineHeight: '24rpx',
- left: '32rpx',
- top: 579+dth+'rpx'
- }
- },
-
- {
- type: 'image',
- src: 'https://s.yun-live.com/images/20210201/d88d56843d43b917e2a28550b2a62723.png',
- css: {
- left: '0rpx',
- top: '90%',
- width: '103rpx',
- height: '103rpx',
- }
- },
- {
- type: 'image',
- src: 'https://s.yun-live.com/images/20210201/247736ffd279276b891ec14db8ed0fd0.png',
- css: {
- left: '600rpx',
- top: '50%',
- width: '56.4rpx',
- height: '56.4rpx',
- }
- },
- {
- type: 'view',
- use:'qrcode-view',
- css: {
- left: '400rpx',
- top: 520+dth+'rpx',
- width: '240rpx',
- height: '240rpx',
- background: '#fff',
- }
- },
- {
- type: 'image',
- src: posterObj1.qrcode,
- use:'qrcode',
- css: {
- left: '410rpx',
- top: 530+dth+'rpx',
- // transform: 'translate(-50%,0)',
- width: '220rpx',
- height: '220rpx',
- }
- },
- ]
- }
- break;
- case 2:
- posterObj={
- width: '670rpx',
- height: h+'rpx',
- background: '#fff',
- borderRadius: '16rpx',
- views: [{
- type: 'image',
- use:'bg',
- src: 'https://s.yun-live.com/images/20210201/78f227bd701da20676c9da9166ce3144.png',
- css: {
- left: '0',
- top: '0',
- width: '100%',
- height: '100%'
- }
- },
- {
- type: 'image',
- src: posterObj1.image,
- css: {
- left: '62rpx',
- top: '84rpx',
- width: '540rpx',
- height: '304rpx',
- borderRadius: '16rpx'
- }
- },
- {
- type: 'text',
- text: posterObj1.title,
- use:'title',
- css: {
- fontSize: '32rpx',
- color: '#1D1D25',
- fontWeight: 'bold',
- lineHeight: '45rpx',
- left: '62rpx',
- top: '420rpx',
- width: '530rpx'
- }
- },
- {
- type: 'text',
- text:posterObj1.title1,
- use:'title1',
- css: {
- fontSize: '28rpx',
- fontWeight: 'bold',
- color: '#1D1D25',
- lineHeight: '28rpx',
- left: '62rpx',
- top: 515+dth+'rpx'
- }
- },
- {
- type: 'text',
- text: '扫描识别二维码',
- use:'title2',
- css: {
- fontSize: '24rpx',
- color: '#6CB37A',
- lineHeight: '24rpx',
- left: '62rpx',
- top: 559+dth+'rpx'
- }
- },
- {
- type: 'view',
- use:'qrcode-view',
- css: {
- left: '365rpx',
- top: 500+dth+'rpx',
- width: '240rpx',
- height: '240rpx',
- background: '#fff',
- }
- },
- {
- type: 'image',
- src: posterObj1.qrcode,
- use:'qrcode',
- css: {
- left: '375rpx',
- top: 510+dth+'rpx',
- // transform: 'translate(-50%,0)',
- width: '220rpx',
- height: '220rpx',
- }
- },]
- }
- break;
- case 3:
- posterObj={
- width: '670rpx',
- height: h+'rpx',
- background: '#fff',
- borderRadius: '16rpx',
- views: [{
- type: 'image',
- use:'bg',
- src: 'https://s.yun-live.com/images/20210201/524ab6a41fe8c7eb57b35df9a547d388.png',
- css: {
- left: '0',
- top: '0',
- width: '100%',
- height: '100%'
- }
- },
- {
- type: 'image',
- src: posterObj1.image,
- css: {
- left: '32rpx',
- top: '44rpx',
- width: '606rpx',
- height: '341rpx',
- borderRadius: '16rpx'
- }
- },
- {
- type: 'text',
- text: posterObj1.title,
- use:'title',
- css: {
- fontSize: '32rpx',
- color: '#1D1D25',
- fontWeight: 'bold',
- lineHeight: '45rpx',
- left: '32rpx',
- top: '410rpx',
- width: '530rpx'
- }
- },
- {
- type: 'text',
- text:posterObj1.title1,
- use:'title1',
- css: {
- fontSize: '28rpx',
- fontWeight: 'bold',
- color: '#1D1D25',
- lineHeight: '28rpx',
- left: '32rpx',
- top: 525+dth+'rpx'
- }
- },
- {
- type: 'text',
- text: '扫描识别二维码',
- use:'title2',
- css: {
- fontSize: '24rpx',
- color: '#6CB37A',
- lineHeight: '24rpx',
- left: '32rpx',
- top: 569+dth+'rpx'
- }
- },
-
- {
- type: 'view',
- use:'qrcode-view',
- css: {
- left: '400rpx',
- top: 500+dth+'rpx',
- width: '240rpx',
- height: '240rpx',
- background: '#fff',
- }
- },
- {
- type: 'image',
- src: posterObj1.qrcode,
- use:'qrcode',
- css: {
- left: '410rpx',
- top: 510+dth+'rpx',
- // transform: 'translate(-50%,0)',
- width: '220rpx',
- height: '220rpx',
- }
- },]
- }
- // this.posterObj1.backgroundType='image'
- // this.posterObj1.background='https://s.yun-live.com/images/20210201/524ab6a41fe8c7eb57b35df9a547d388.png';
- // this.posterObj1.width='606rpx',
- // this.posterObj1.height='341rpx',
- // this.posterObj1.titleCssColor='#1D1D25'
- // this.posterObj1.title1CssColor='#1D1D25'
- // this.posterObj1.title2CssColor='#6CB37A'
- // break;
- default:
- break;
- }
- return posterObj
- }
- export default {
- baseUrl,
- baseRequest,
- TokenRequest,
- wxlogin,
- getPhone,
- syncInfo,
- makeCanvasData
- }
|