123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814 |
- <template>
- <view class="content">
- <view class="bg"></view>
- <view class="cont-box">
- <!-- <view class="user-cont">
- <view class="user-box" v-if="user!=null" >
- <view class="left">
- <image :src="user.avatar"></image>
- <view class="user" >
- <view class="username">{{user.name}}</view>
- <view class="account" v-if="user.gender!=null" >{{user.gender==1?'男':'女'}}</view>
- </view>
- </view>
- <view class="right" >
- <image src="../../static/images/right_arrow.png"></image>
- </view>
- </view>
- <view class="company" v-if="user!=null">
- <image src="../../static/images/icon_comp.png"></image>
- <view class="name">{{user.companyName}}</view>
- </view>
- </view> -->
-
- <view class="menu-box">
- <view class="title-box">
- <image class="icon" src="../../static/images/office.png"></image>
- <view class="title">常用功能</view>
- </view>
- <view class="line"></view>
- <view class="menus">
- <view class="menu-item" @click="navTo('/pages/user/qwSop/sopLogsList?externalUserId='+externalUserId)">
- <image src="../../static/images/menu_info.png"></image>
- <view class="m-name">SOP记录</view>
- </view>
- <view class="menu-item" @click="clear()">
- <image src="../../static/images/menu_info.png"></image>
- <view class="m-name">清除缓存</view>
- </view>
- </view>
-
- </view>
- <!-- <view class="text">corpid:{{corpId}}</view>
- <view class="text">code:{{code}}</view>
- <view class="text">allurl:{{allUrl}}</view>
- <view class="text">url:{{url}}</view> -->
-
- </view>
- </view>
- </template>
- <script>
-
- import { getConfigSignature,getQwExternalContactDetails } from '@/api/common.js'
- import { getQwSopLogsByJsApi,updateQwSopLogs,deleteQwSopLogsByJsApi} from '@/api/qwSop.js'
-
- export default {
- data() {
- return {
- initInterval:null,
- externalUserId:null,
- userId:null,
- wxSdk:null,
- corpId:"",
- code:"",
- url:"",
- show:false,
- sendFlag:false,
- // websocketFlag:false,
- isInit:false,//是否定位
- user:{
- gender:null,
- name:"",
- avatar:"",
- remarkMobiles:""
- },
- }
- },
- onLoad(options) {
- this.url=window.location.href;
- console.log(this.url)
- this.code=options.code;
- this.corpId=options.corpId;
- uni.setStorageSync("corpId",this.corpId);
- this.externalUserId=uni.getStorageSync("externalUserId");
- var userId=uni.getStorageSync("qwUserId");
- if(userId!=null&&userId!=undefined&&userId!=""){
- this.userId=userId;
- }
- // console.log(this.externalUserId)
- // console.log(this.userId)
- // var that=this;
- // if(this.externalUserId!=null&&this.externalUserId!=undefined&&this.userId!=null&&this.userId!=undefined){
- // console.log("获取外部联系人")
- // this.getQwExternalContactDetails()
- // that.initInterval=setInterval(function(){
- // if(that.isInit){
- // clearInterval(that.initInterval);
- // that.getQwSopLogsByJsApi();
- // setInterval(function(){
- // that.getQwSopLogsByJsApi();
- // },60000);
- // }
- // },200)
- // }
- // else{
- // console.log("获取配置信息")
-
- // }
- this.getConfigSignature()
- this.wxSdk=uni.getStorageSync("wxSdk");
- var that=this;
- uni.$on('deleteId', () => {
- console.log("删除外部联系人");
- that.deleteQwSopLogsByJsApi(that.nextExternalUserId)
- })
-
- uni.$on('init', (data) => {
- console.log(data);
- that.isInit=data==1?true:false;
-
- })
- uni.$on('reload', (data) => {
- that.openNextChat(that.externalUserId)
- })
-
-
- uni.$on('sendStatus', (data) => {
- console.log("更新发送状态1");
- that.sendFlag=false;
-
- })
- uni.$on('getLogs', (data) => {
- console.log("接口调用失败");
- that.getQwSopLogsByJsApi()
-
- })
-
- // uni.$on('websocket', (data) => {
- // console.log("插件状态"+data);
- // if(data==0){
- // that.websocketFlag=false;
- // uni.showToast({
- // title: "插件离线",
- // icon: 'none',
- // });
- // }
- // else if(data==1){
- // that.websocketFlag=true;
- // uni.showToast({
- // title: "插件在线",
- // icon: 'none',
- // });
- // }
-
- // })
-
-
-
-
- },
- onShow() {
- //https://blog.csdn.net/u013361179/article/details/132336082?spm=1001.2014.3001.5501
- //https://www.cnblogs.com/goloving/p/16742077.html
-
- },
- methods: {
- clear(){
- uni.setStorageSync("externalUserId",null);
- uni.setStorageSync("qwUserId",null);
-
- },
- getQwSopLogsByJsApi(){
- var data = {
- corpId:this.corpId,
- externalUserId:this.externalUserId,
- qwUserId:this.userId,
- };
- var that=this;
- try{
- getQwSopLogsByJsApi(data).then(
- res => {
- if(res.data.sendList!=null){
- console.log("获取待发送记录"+res.data.sendList.length)
- }
- else{
- console.log("获取待发送记录null")
- }
- console.log(res)
- //判断插件是否INIT
- if(that.isInit){
- console.log("已初始化")
- that.nextExternalUserId=res.data.nextExternalUserId;
- if(res.data.sendList!=null&&res.data.sendList.length>0){
- console.log("开始发送")
- that.sendSop(res.data.sendList,res.data.nextExternalUserId);
- }
- else if(res.data.nextExternalUserId!=null){
- console.log("切换页面")
- that.openNextChat(res.data.nextExternalUserId);
- var data={cmd:"switchPage"};
- uni.$emit('sendMsg',data);
- }
- else{
-
- }
- }
- else{
-
- }
-
-
- },
- rej => {
- console.log("接口获取数据失败")
- }
- );
- }
- catch(e){
-
- }
-
- },
- openNextChat(nextExternalUserId){
- // var that=this;
- // jWeixin.invoke('openUserProfile', {
- // "type": 2, //1表示该userid是企业成员,2表示该userid是外部联系人
- // "userid": nextExternalUserId //可以是企业成员,也可以是外部联系人
- // }, function(res) {
- // console.log(res)
- // if(res.err_msg == "openUserProfile:ok") {
-
- // }
- // else{
- // uni.showToast({
- // title: nextExternalUserId+"不属于本人",
- // icon: 'none',
- // });
- // that.deleteQwSopLogsByJsApi(nextExternalUserId);
-
- // }
- // });
- uni.setStorageSync("externalUserId",nextExternalUserId);
- jWeixin.openEnterpriseChat({
- // 注意:userIds和externalUserIds至少选填一个。内部群最多2000人;外部群最多500人;如果有微信联系人,最多40人
- externalUserIds: nextExternalUserId, // 参与会话的外部联系人列表,格式为userId1;userId2;…,用分号隔开。
- groupName: '', // 会话名称。单聊时该参数传入空字符串""即可。
- chatId: "", // 若要打开已有会话,需指定此参数。如果是新建会话,chatId必须为空串
- success: function(res) {
- console.log(res);
- uni.showToast({
- title: "切换成功",
- icon: 'none',
- });
- var data={cmd:"switchPage"};
- uni.$emit('sendMsg',data);
- },
- fail: function(res) {
- console.log(res);
- uni.showToast({
- title: "切换失败",
- icon: 'none',
- });
- var data={cmd:"switchPage"};
- uni.$emit('sendMsg',data);
-
- }
- });
-
- },
- async sendMsg(msgItem){
- var that=this;
- that.sendFlag=true;
- if(msgItem.contentType==1){
- //await that.sleep(500);
- jWeixin.invoke('sendChatMessage', {
- msgtype:"text", //消息类型,必填
- enterChat: true,
- text: {
- content:msgItem.value, //文本内容
- }
- }, function(res) {
- console.log("发送成功")
- console.log(res)
- if (res.err_msg == 'sendChatMessage:ok') {
-
- uni.showToast({
- title: "发送中请勿操作",
- icon: 'none',
- });
- var data={cmd:"enter"};
- uni.$emit('sendMsg',data);
-
-
- }
- })
- }
- else if(msgItem.contentType==2){
- //图片
- //await that.sleep(2000);
- var data={cmd:"img",data:msgItem.imgUrl};
- uni.$emit('sendMsg',data);
-
-
- }
- else if(msgItem.contentType==5){
- //图片
- //await that.sleep(2000);
- var data={cmd:"file",data:msgItem.fileUrl};
- uni.$emit('sendMsg',data);
-
- }
- else if(msgItem.contentType==6){
- //图片
- //await that.sleep(2000);
- var data={cmd:"video",data:msgItem.videoUrl};
- uni.$emit('sendMsg',data);
-
- }
- else if(msgItem.contentType==3){
- //await that.sleep(500);
- jWeixin.invoke('sendChatMessage', {
- msgtype:"news", //消息类型,必填
- enterChat: true,
- news:
- {
- link: msgItem.linkUrl, //H5消息页面url 必填
- title: msgItem.linkTitle, //H5消息标题
- desc: msgItem.linkDescribe, //H5消息摘要
- imgUrl: msgItem.linkImageUrl, //H5消息封面图片URL
- }
-
- }, function(res) {
- console.log("发送成功")
- console.log(res)
- if (res.err_msg == 'sendChatMessage:ok') {
-
- uni.showToast({
- title: "回车发送",
- icon: 'none',
- });
- var data={cmd:"enter"};
- uni.$emit('sendMsg',data);
-
- }
- })
- }
- var time=50;
- while(time>0){
- console.log("time")
- console.log(time)
- if(!that.sendFlag){
- break;
- }
- else{
- time--;
- await this.sleep(200);
-
- }
- }
-
- },
- sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- },
- async sendSop(sendList,nextExternalUserId){
- var that=this;
- console.log("开始发消息");
- for (const item of sendList) {
- console.log(item);
- var msgs=JSON.parse(item.contentJson);
- var that=this;
- for(var i=0;i<msgs.setting.length;i++){
- var msgItem=msgs.setting[i]
- console.log("消息");
- console.log(msgItem);
-
- await that.sendMsg(msgItem)
- }
- //更新消息
- that.updateQwSopLogs(item.id);
- }
- await that.sleep(200);
- if(nextExternalUserId!=null){
- that.openNextChat(nextExternalUserId)
-
- }
- else{
- setTimeout(function(){
- that.getQwSopLogsByJsApi()
- },60000);
- }
-
- },
- updateQwSopLogs(id){
- console.log("更新发送状态")
- var data = {
- id:id,
- sendStatus:1,
- receivingStatus:1
- };
- var that=this;
- updateQwSopLogs(data).then(
- res => {
-
-
- },
- rej => {}
- );
- },
- deleteQwSopLogsByJsApi(externalUserId){
- var that=this;
- console.log("删除发送状态")
- var data = {
- corpId:this.corpId,
- externalUserId:externalUserId,
- qwUserId:this.userId,
- };
- console.log(data)
- var that=this;
- deleteQwSopLogsByJsApi(data).then(
- res => {
- that.getQwSopLogsByJsApi()
-
- },
- rej => {
- that.getQwSopLogsByJsApi()
- }
- );
- },
- getConfigSignature(){
- var data = {
- corpId: this.corpId,
- url: this.url,
- code: this.code
- };
- if(this.userId!=null){
- data.isGetUserId=0;
- }
- else{
- data.isGetUserId=1;
- }
- var that=this;
- getConfigSignature(data).then(
- res => {
- console.log(res)
- if(res.code==200){
- const agentConfigSignature = res.config.agentConfigSignature;
- const configSignature = res.config.configSignature;
- const corpId = res.config.corpId;
- const nonceStr = res.config.nonceStr;
- const timestamp = res.config.timestamp;
- const agentId = res.config.agentId;
- if(res.config.userid!=null&&res.config.userid!=''){
- this.userId = res.config.userid;//当前员工ID
- uni.setStorageSync("qwUserId",this.userId);
- console.log("获取到USERID")
- }
- else{
- console.log("不需要获取USERID")
- }
- console.log(this.userId)
- jWeixin.config({
- beta: true,
- debug: false,
- appId: corpId,
- timestamp: timestamp,
- nonceStr: nonceStr,
- signature: configSignature,
- jsApiList: ['getCurExternalContact','sendChatMessage','openEnterpriseChat']
- });
- // const newSignature={
- // 'timestamp':timestamp,
- // 'nonceStr':nonceStr,
- // 'signature':configSignature,
- // }
- // ww.register({
- // corpId: corpId, // 必填,当前用户企业所属企业ID
- // jsApiList: ['openEnterpriseChat'], // 必填,需要使用的JSAPI列表
- // newSignature // 必填,根据url生成企业签名的回调函数
- // })
- jWeixin.ready(() => {
- jWeixin.agentConfig({
- corpid: corpId,
- agentid: agentId,
- timestamp: timestamp,
- nonceStr: nonceStr,
- signature: agentConfigSignature,
- jsApiList: ['getCurExternalContact','sendChatMessage','openEnterpriseChat'],
- success: (res) => {
- jWeixin.invoke('getCurExternalContact', {}, async (res) => {
- if (res.err_msg === "getCurExternalContact:ok") {
- that.externalUserId = res.userId;
- // that.getQwExternalContactDetails()
- that.initInterval=setInterval(function(){
- if(that.isInit){
- clearInterval(that.initInterval);
- that.getQwSopLogsByJsApi();
- setInterval(function(){
- that.getQwSopLogsByJsApi();
- },60000);
- }
- },200)
-
- } else {
- // 错误处理
- }
- });
-
- // jWeixin.openEnterpriseChat({
- // // 注意:userIds和externalUserIds至少选填一个。内部群最多2000人;外部群最多500人;如果有微信联系人,最多40人
- // externalUserIds: 'wmfFKfDQAAhvgwhJr9fqkRWjvN0CzFcA', // 参与会话的外部联系人列表,格式为userId1;userId2;…,用分号隔开。
- // groupName: '', // 会话名称。单聊时该参数传入空字符串""即可。
- // chatId: "", // 若要打开已有会话,需指定此参数。如果是新建会话,chatId必须为空串
- // success: function(res) {
- // var chatId = res.chatId; //返回当前群聊ID,仅当使用agentConfig注入该接口权限时才返回chatId
- // // 回调
- // that.externalUserId=res.chatId;
- // console.log(res)
- // setTimeout(function(){
- // jWeixin.invoke('sendChatMessage', {
- // msgtype:"news", //消息类型,必填
- // enterChat: true,
- // text: {
- // content:"你好11111111111111111", //文本内容
- // },
- // news:
- // {
- // link: "https://www.baidu.com/", //H5消息页面url 必填
- // title: "百度一下", //H5消息标题
- // desc: "百度一下你就知道", //H5消息摘要
- // imgUrl: "https://cos.his.cdwjyyh.com/fs/20240914/efc6995ee755489b8a3e0c8413846a4e.jpg", //H5消息封面图片URL
- // },
- // }, function(res) {
-
- // if (res.err_msg == 'sendChatMessage:ok') {
- // //发送成功
- // uni.showToast({
- // title: "回车发送",
- // icon: 'none',
- // });
- // }
- // })
- // },500);
-
-
-
- // },
- // fail: function(res) {
- // if(res.errMsg.indexOf('function not exist') > -1){
- // alert('版本过低请升级')
- // }
- // }
- // });
- },
- fail: (res) => {
- console.error('agentConfig fail:', res);
- },
-
-
- });
- });
- jWeixin.error((res) => {
- console.error('wx.error:', res);
- });
-
- }
- else{
- console.log("获取USERID失败")
- // setTimeout(function(){
- // window.location.reload();
- // },5000);
-
- }
-
- },
- rej => {}
- );
- },
- navTo(url){
- console.log(url)
- uni.navigateTo({
- url
- })
- },
- getQwExternalContactDetails(){
- var that=this
- var data = {
- corpId: this.corpId,
- userId:this.userId,
- externalUserId:this.externalUserId,
- };
- getQwExternalContactDetails(data).then(res => {
- if(res.code==200){
- this.user=res.data;
-
- }else{
-
- }
- });
- },
- }
- }
- </script>
- <style lang="scss">
- page{
- height: 100%;
- background: #f6f6f6;
- }
- </style>
- <style scoped lang="scss">
- .content{
- position: relative;
- height: 100%;
- width: 100%;
- .bg{
- width: 100%;
- height: 400upx;
- position: absolute;
- top: 0;
- left: 0;
- z-index: 1;
- background: linear-gradient(to bottom,#115296, #111);
- // border-radius: 0rpx 0rpx 60rpx 60rpx;
- }
- .cont-box{
- position: relative;
- z-index: 2;
- padding: 30rpx 30rpx 200rpx;
- .user-cont{
- box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
- padding: 30rpx;
- background-color: #fff;
- border-radius: 15rpx;
- .user-box{
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: flex-start;
- .left{
- flex:1;
- display: flex;
- align-items: center;
- justify-content: flex-start;
- image{
- border-radius: 50%;
- width:120rpx;
- height:120rpx;
- }
- .user{
- margin-left: 20rpx;
- width: calc(100% - 140rpx);
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- justify-content: flex-start;
- .username{
- font-size: 38rpx;
- font-family: PingFang SC;
- color: #111;
- font-weight: bold;
- }
- .account{
- padding: 5rpx 20rpx;
- border-radius: 30rpx;
- background-color: #115296;
- margin-top: 20rpx;
- font-size: 24rpx;
- font-family: PingFang SC;
- color: #fff;
- }
- }
- }
- .right{
- image{
- width: 15rpx;
- height:30rpx;
- }
-
- }
-
- }
- .company{
- margin-top: 30rpx;
- display: flex;
- align-items: center;
- justify-content: flex-start;
- image{
- width:40rpx;
- height:40rpx;
- }
- .name{
- margin-left: 15rpx;
- font-size: 28rpx;
- color: #111;
- }
- }
- }
-
- .menu-box{
- box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
- width: 100%;
- margin-top: 30rpx;
- padding: 30rpx;
- background-color: #fff;
- border-radius: 15rpx;
- .title-box{
- display: flex;
- align-items: center;
- justify-content: flex-start;
- .icon{
- width: 30rpx;
- height:30rpx;
- }
- .title{
- margin-left: 10rpx;
- font-size: 28rpx;
- font-family: PingFang SC;
- color: #111;
- }
- }
- .line{
- margin-top: 15rpx;
- height: 0.5rpx;
- width: 100%;
- background-color: #efefef;
- }
- .menus{
- margin-top: 30rpx;
- display: flex;
- align-items: center;
- justify-content: flex-start;
- flex-wrap: wrap;
- }
- .menu-item{
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- width: 25%;
- margin-bottom: 20rpx;
- image{
- width:60rpx;
- height:60rpx;
- }
- .m-name{
- margin-top: 10rpx;
- font-size: 24rpx;
- font-family: PingFang SC;
- color: #111;
- }
- }
-
- }
- .menu-box1{
- width: 100%;
- margin-top: 30rpx;
- padding: 0rpx 30rpx;
- background-color: #fff;
- border-radius: 15rpx;
- .menu-item{
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: flex-start;
- line-height: 100rpx;
- .left{
- flex:1;
- display: flex;
- align-items: center;
- justify-content: flex-start;
- image{
- width: 30rpx;
- height:30rpx;
- }
- .label{
- margin-left: 10rpx;
- }
- }
- .right{
- image{
- width: 10rpx;
- height:15rpx;
- }
-
- }
- }
- }
- }
- }
- .btn-box{
- margin: 60rpx 0rpx 30rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- .sub-btn{
- // box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
- border: 1rpx solid #f8f8f8;
- background: #FFFFFF;
- width: 100%;
- height: 88upx;
- line-height: 88upx;
- text-align: center;
- font-size: 30upx;
- font-family: PingFang SC;
- color: #111;
- }
- }
- .text{
- width: 100%;
- font-size: 24rpx;
-
- }
- </style>
|