Commit 4457b445 by liwk

commit

1 parent e7de3d1e
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
to continue.</strong> to continue.</strong>
</noscript> </noscript>
<div id="app"></div> <div id="app"></div>
<script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> <!-- <script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> -->
<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script> <script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script>
<!-- 使用CDN加速的JS文件,配置在vue.config.js下 --> <!-- 使用CDN加速的JS文件,配置在vue.config.js下 -->
<% for (var i in htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.js) { %> <% for (var i in htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.js) { %>
...@@ -27,4 +27,4 @@ ...@@ -27,4 +27,4 @@
<!-- built files will be auto injected --> <!-- built files will be auto injected -->
</body> </body>
</html> </html>
\ No newline at end of file \ No newline at end of file
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
* @LastEditTime: 2021-06-17 18:23:27 * @LastEditTime: 2021-06-17 18:23:27
*/ */
import ssoApi from './ssoApi' import ssoApi from './ssoApi'
import wxConfig from './wxConfig' import wx_config from './wxConfig'
import shopmallApi from './shopmallApi' import shopmallApi from './shopmallApi'
export { export {
ssoApi, ssoApi,
wxConfig, wx_config,
shopmallApi shopmallApi
} }
\ No newline at end of file \ No newline at end of file
...@@ -2,37 +2,43 @@ import util from '@/utils/util' ...@@ -2,37 +2,43 @@ import util from '@/utils/util'
import { Notify } from 'vant' import { Notify } from 'vant'
class WxConfig { class WxConfig {
constructor(jsApiList) { constructor(jsApiList) {
jsApiList.map(e => {
if (e == 'chooseImage') jsApiList.push('getLocalImgData')
})
let [redirectUrl] = window.location.href.split('#') let [redirectUrl] = window.location.href.split('#')
const corpId = util.getLocalStorage('dj_scrm_corpId') const { corpId } = util.getLocalStorage('dj_scrm_corpId')
/** 获取企微应用AgentConfig */ /** 获取企微应用AgentConfig */
let data = { let data = {
corpId, corpId,
method: 'scrm.api.work.wechat.get.agent.config', method: 'scrm.api.work.wechat.get.agent.config',
url: redirectUrl, url: redirectUrl,
appCode: 'DJQWZS' appCode: 'DJQWGJ'
} }
window.$HTTP({ window.$HTTP({
url: '/rop-scrm-wechat/router', url: '/rop-scrm-wechat/router',
data data
}).then(res => { }).then(obj => {
console.log(res) if (obj) {
if (res) { console.log(obj)
this.setConfig({ wx.agentConfig({
...res.data, corpid: obj.corpId, // 必填,企业微信的corpid,必须与当前登录的企业一致
jsApiList agentid: obj.agentId, // 必填,企业微信的应用id (e.g. 1000247)
timestamp: obj.timestamp, // 必填,生成签名的时间戳
nonceStr: obj.nonceStr, // 必填,生成签名的随机串
signature: obj.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法,
jsApiList,
success(res) {
console.log(res)
},
fail(err) {
console.log(err)
}
}) })
} else { } else {
Notify('网络异常') Notify('网络异常')
} }
}) })
} }
setConfig(params) {
let obj = {}
Object.keys(params).map(key => {
if (params[key]) obj[key] = params[key]
})
wx.agentConfig(obj)
}
getContext(callBack) { getContext(callBack) {
/** /**
* entry String 场景值 * entry String 场景值
...@@ -140,6 +146,136 @@ class WxConfig { ...@@ -140,6 +146,136 @@ class WxConfig {
}) })
}) })
} }
/**打开会话 */
openEnterpriseChat({
externalUserIds = [],
groupName = '',
userIds = [],
chatId = ''
}) {
return new Promise((resolve) => {
userIds = userIds.join(';')
externalUserIds = externalUserIds.join(';')
wx.openEnterpriseChat({
// 注意:userIds和externalUserIds至少选填一个。内部群最多2000人;外部群最多500人;如果有微信联系人,最多40人
userIds, //参与会话的企业成员列表,格式为userid1;userid2;...,用分号隔开。
externalUserIds, // 参与会话的外部联系人列表,格式为userId1;userId2;…,用分号隔开。
groupName, // 会话名称。单聊时该参数传入空字符串""即可。
chatId, // 若要打开已有会话,需指定此参数。如果是新建会话,chatId必须为空串
success(res) {
resolve(res)
},
fail(res) {
if (res.errMsg.indexOf('function not exist') > -1) {
Notify('版本过低请升级')
}
}
})
})
}
/**企业微信扫一扫 */
scanQRCode(needResult) {
return new Promise((resolve) => {
wx.scanQRCode({
desc: 'scanQRCode desc',
needResult, // 默认为0,扫描结果由企业微信处理,1则直接返回扫描结果,
scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是条形码(一维码),默认二者都有
success(res) {
resolve(res)
},
error: function(res) {
if (res.errMsg.indexOf('function_not_exist') > 0) {
alert('版本过低请升级')
}
}
})
})
}
/**获取本地图片接口 */
getLocalImgData() {
return new Promise((resolve) => {
wx.getLocalImgData({
localId: '', // 图片的localID
success(res) {
resolve(res) //localData是图片的base64数据,可以用img标签显示
}
})
})
}
/**拍照或从手机相册中选图接口 */
chooseImage(count = 1) {
return new Promise((resolve) => {
wx.chooseImage({
count, // 默认1
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success(res) {
let { localIds } = res
let imgs = []
localIds.map((e, index) => {
wx.getLocalImgData({
localId: e,
success(img) {
imgs.push(img)
if (index == localIds.length - 1) resolve(imgs)
}
})
})
}
})
})
}
/**预览图片接口 */
previewImage(obj) {
/**current 当前显示图片的http链接
* urls 需要预览的图片http链接列表
*/
wx.previewImage(obj)
}
/**上传图片接口 */
uploadImage(localId) {
return new Promise((resolve) => {
wx.uploadImage({
localId, // 需要上传的图片的本地ID,由chooseImage接口获得
isShowProgressTips: 1, // 默认为1,显示进度提示
success(res) {
resolve(res) // 返回图片的服务器端ID
/**备注:上传图片有效期3天,可用素材管理接口下载图片到自己的服务器,此处获得的 serverId 即 media_id。 */
}
})
})
}
/**使用企业微信内置地图查看位置接口 */
openLocation(obj) {
/**
latitude: 0, // 纬度,浮点数,范围为90 ~ -90
longitude: 0, // 经度,浮点数,范围为180 ~ -180。
name: '', // 位置名
address: '', // 地址详情说明
scale, // 地图缩放级别,整形值,范围从1~28。默认为16
*/
wx.openLocation(obj)
}
/**获取地理位置接口 */
getLocation(type = 'wgs84') {
return new Promise((resolve) => {
wx.getLocation({
type, // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success(res) {
resolve(res)
}
})
})
}
} }
export default WxConfig export default WxConfig
\ No newline at end of file \ No newline at end of file
...@@ -27,11 +27,15 @@ export default { ...@@ -27,11 +27,15 @@ export default {
return [] return []
} }
}, },
sticky: Boolean sticky: Boolean,
index: {
type: Number,
default: 0
}
}, },
data () { data () {
return { return {
tabIndex: 0 tabIndex: this.index
} }
}, },
mounted () { mounted () {
......
...@@ -21,7 +21,6 @@ import { bus, tools, store as local } from './utils' ...@@ -21,7 +21,6 @@ import { bus, tools, store as local } from './utils'
import './utils/util' import './utils/util'
import 'components' import 'components'
import { components } from '@/plugins/vant' import { components } from '@/plugins/vant'
import { Http } from 'glsx-common'
components.forEach(component => Vue.use(component)) components.forEach(component => Vue.use(component))
Vue.prototype.api = api Vue.prototype.api = api
Vue.prototype.bus = bus Vue.prototype.bus = bus
...@@ -40,16 +39,14 @@ Vue.prototype.to = function(name, params) { ...@@ -40,16 +39,14 @@ Vue.prototype.to = function(name, params) {
Vue.config.productionTip = false Vue.config.productionTip = false
import VConsole from 'vconsole' import VConsole from 'vconsole'
const vConsole = new VConsole() // const vConsole = new VConsole()
const isMock = true const isMock = true
fetchConfig(!isMock).then(res => { fetchConfig(!isMock).then(res => {
// 从配置服务器获取动态配置 // 从配置服务器获取动态配置
// 设置 js中可以访问 $cdn // 设置 js中可以访问 $cdn
Vue.use(cfg) Vue.use(cfg)
window.$baseUrl = res.request.baseURL window.$fetchConfig = res
window.$HTTP = new Http({...res, alert: components.Notify })
console.log(window.$HTTP)
/**登录过期 重新登录 */ /**登录过期 重新登录 */
window.reLogin = () => { window.reLogin = () => {
console.log(123) console.log(123)
......
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
* @LastEditTime: 2021-07-06 12:02:21 * @LastEditTime: 2021-07-06 12:02:21
*/ */
import { ssoApi } from '@/api' import { ssoApi } from '@/api'
import { store } from 'utils' import { store, util } from 'utils'
import util from '@/utils/util' import { Http } from 'glsx-common'
import { Notify } from 'vant'
const state = { const state = {
pageMeta: '', pageMeta: '',
keepAlives: [], keepAlives: [],
...@@ -57,17 +58,20 @@ const actions = { ...@@ -57,17 +58,20 @@ const actions = {
removeKeep({ commit }, names) { removeKeep({ commit }, names) {
commit('REMOVE_KEEP', names) commit('REMOVE_KEEP', names)
}, },
login() { login({ dispatch }) {
let [redirectUrl] = window.location.href.split('?') let [redirectUrl] = window.location.href.split('?')
const code = getParams('code') const code = getParams('code')
if (code) { if (code) {
const corpId = util.getLocalStorage('dj_scrm_corpId') const { corpId } = util.getLocalStorage('dj_scrm_corpId')
ssoApi.login({ ssoApi.login({
code, code,
corpId corpId
}).then(({ code, data, message }) => { }).then(({ code, data, message }) => {
let url = `${window.$baseUrl}/dj-scrm-wx-work-main/#/` console.log(data, code)
let route = state.lastPath == 'home' ? '' : state.lastPath // const { baseURL } = window.$fetchConfig.request
const [baseURL] = redirectUrl.split('/dj-scrm-wx-work-main/')
let url = `${baseURL}/dj-scrm-wx-work-main/#/`
let route = state.lastPath == 'home' ? '' : state.lastPath || ''
state.showWindow = true state.showWindow = true
if (code == '0') { if (code == '0') {
if (data.loginList.length) { if (data.loginList.length) {
...@@ -75,11 +79,30 @@ const actions = { ...@@ -75,11 +79,30 @@ const actions = {
util.setLocalStorage('dj_scrm_loginToken', data.loginToken) util.setLocalStorage('dj_scrm_loginToken', data.loginToken)
util.setLocalStorage('dj_scrm_accountList', data.loginList) util.setLocalStorage('dj_scrm_accountList', data.loginList)
let redirect_uri = encodeURI(`${redirectUrl}${route}`) let redirect_uri = encodeURI(`${redirectUrl}${route}`)
window.location.replace(`${url}common/accountList?redirect_uri=${redirect_uri}`) //先注释 window.location.replace(`${url}common/accountList?redirect_uri=${redirect_uri}`)
//以下是 本地调试多账号默认第一个
let [userInfo] = data.loginList
let { merchantId, accountName } = userInfo
let loginAccount = accountName
ssoApi.selectAccount({
loginAccount,
merchantId,
loginToken: data.loginToken,
loginSource: 'WW',
loginType: 3
}).then(res => {
util.removeLocalStorage('dj_scrm_loginToken')
util.removeLocalStorage('dj_scrm_accountList')
util.setLocalStorage('dj_scrm_userInfo', res.data)
util.setSessionId(res.data.sessionId)
dispatch('registerHttp', res.data.sessionId)
window.location.replace(`${redirectUrl}${route}`)
})
} else { } else {
let [userInfo] = data.loginList let [userInfo] = data.loginList
util.setLocalStorage('dj_scrm_userInfo', userInfo) util.setLocalStorage('dj_scrm_userInfo', userInfo)
util.setLocalStorage('dj_scrm_session_id', userInfo.sessionId) util.setSessionId(userInfo.sessionId)
registerHttp(userInfo.sessionId)
// 只有一个账号 history.back() // 只有一个账号 history.back()
console.log(`${redirectUrl}${route}`) console.log(`${redirectUrl}${route}`)
window.location.replace(`${redirectUrl}${route}`) window.location.replace(`${redirectUrl}${route}`)
...@@ -96,28 +119,35 @@ const actions = { ...@@ -96,28 +119,35 @@ const actions = {
}) })
} else { } else {
util.showLoading() util.showLoading()
let corpId = getParams('corpId') //从链接获取 let appid = getParams('corpId') //从链接获取
if (!corpId) corpId = 'ww7ee69c648ae1b7e6' let dj_scrm = util.getLocalStorage('dj_scrm_corpId')
util.setLocalStorage('dj_scrm_corpId', corpId) if (!appid) appid = dj_scrm && dj_scrm.corpId || 'ww7ee69c648ae1b7e6'
//
util.setLocalStorage('dj_scrm_corpId', { corpId: appid })
// 'ww657a2d4ae89a4424' // 'ww657a2d4ae89a4424'
const wxUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize' const wxUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize'
window.location.replace(`${wxUrl}?appid=${corpId}&redirect_uri=${encodeURIComponent(redirectUrl)}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`) window.location.href = `${wxUrl}?appid=${appid}&redirect_uri=${encodeURIComponent(redirectUrl)}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
} }
}, },
navigation({ dispatch }) { navigation({ dispatch }) {
util.showLoading() util.showLoading()
const sessionId = getParams('sessionId') const sessionId = getParams('sessionId')
const storage_sessionId = util.getLocalStorage('dj_scrm_session_id') const storage_sessionId = util.getSessionId()
if (sessionId || storage_sessionId) { if (sessionId || storage_sessionId) {
state.showWindow = true state.showWindow = true
util.setLocalStorage('dj_scrm_session_id', sessionId || storage_sessionId) util.setSessionId(sessionId || storage_sessionId)
registerHttp(sessionId || storage_sessionId)
} else { } else {
registerHttp()
dispatch('login') dispatch('login')
return return
} }
state.showWindow = true state.showWindow = true
} }
} }
const registerHttp = (sessionId = '') => {
window.$HTTP = new Http({...window.$fetchConfig, alert: Notify, headers: { token: sessionId } })
}
const getParams = name => { const getParams = name => {
let [url, paramsList] = window.location.href.split('?') let [url, paramsList] = window.location.href.split('?')
if (!paramsList) return name ? null : {} if (!paramsList) return name ? null : {}
......
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
* @LastEditTime: 2021-06-20 12:49:11 * @LastEditTime: 2021-06-20 12:49:11
*/ */
import bus from './eventBus' import bus from './eventBus'
import util from './util'
import * as tool from './tools' import * as tool from './tools'
const { debounce, throttle, ...tools } = tool const { debounce, throttle, ...tools } = tool
import * as constants from './constants' import * as constants from './constants'
import store from './store' import store from './store'
export { bus, tools, debounce, throttle, constants, store }
\ No newline at end of file \ No newline at end of file
export { bus, tools, debounce, throttle, constants, store, util }
\ No newline at end of file \ No newline at end of file
...@@ -79,6 +79,12 @@ const touchstart = e => { ...@@ -79,6 +79,12 @@ const touchstart = e => {
const touchend = e => { const touchend = e => {
e.target.classList.remove('btn-on-leave') e.target.classList.remove('btn-on-leave')
} }
const setSessionId = val => {
window.localStorage.setItem('dj_scrm_session_id', val)
}
const getSessionId = () => {
return window.localStorage.getItem('dj_scrm_session_id')
}
const setLocalStorage = (key, item) => { const setLocalStorage = (key, item) => {
window.localStorage.setItem(key, JSON.stringify(item)) window.localStorage.setItem(key, JSON.stringify(item))
} }
...@@ -164,6 +170,8 @@ const utils = { ...@@ -164,6 +170,8 @@ const utils = {
makePhoneCall, makePhoneCall,
isFullSucreen, isFullSucreen,
watchPageBack, watchPageBack,
setSessionId,
getSessionId,
showLoading, showLoading,
hideLoading, hideLoading,
refreshPage, refreshPage,
......
...@@ -51,7 +51,8 @@ ...@@ -51,7 +51,8 @@
</template> </template>
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
let test = false import { wx_config } from '@/api'
const WX = new wx_config(['shareToExternalContact'])
export default { export default {
name: '', name: '',
data () { data () {
...@@ -80,10 +81,12 @@ export default { ...@@ -80,10 +81,12 @@ export default {
methods: { methods: {
jump () { jump () {
window.$back = true window.$back = true
this.jumpChildrenPage('list')
}, },
change (index) { change (index) {
this.tabIndex = index this.tabIndex = index
WX.shareToExternalContact().then(res => {
console.log(res)
})
}, },
onSelect ({ type }) { onSelect ({ type }) {
console.log(type) console.log(type)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
:data="['会员套餐','门店商品']" :data="['会员套餐','门店商品']"
@change="change" @change="change"
sticky sticky
:index="tabIndex"
></tab> ></tab>
<scroll-view :class="['list-box']"> <scroll-view :class="['list-box']">
<div :class="[`type-${tabIndex}`]"> <div :class="[`type-${tabIndex}`]">
......
...@@ -51,7 +51,7 @@ const spritesmithFunction = data => { ...@@ -51,7 +51,7 @@ const spritesmithFunction = data => {
} }
module.exports = { module.exports = {
publicPath: IS_PROD ? './' : '/dj-scrm-wx-work-main/attachment-activity/', // 署应用包时的基本 URL。 vue-router hash 模式使用 publicPath: IS_PROD ? './' : '/dj-scrm-wx-work-main/', // 本地调试时需登录时使用
// publicPath: IS_PROD ? './' : '/dj-scrm-wx-work-attachment-activity/', // 署应用包时的基本 URL。 vue-router hash 模式使用 // publicPath: IS_PROD ? './' : '/dj-scrm-wx-work-attachment-activity/', // 署应用包时的基本 URL。 vue-router hash 模式使用
// publicPath: '/dj-scrm-wx-work-attachment-activity/', // 署应用包时的基本 URL。 vue-router history模式使用 // publicPath: '/dj-scrm-wx-work-attachment-activity/', // 署应用包时的基本 URL。 vue-router history模式使用
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!