我在MS团队中有一个现有的扩展应用程序(Node.js)。我对QR或条形码扫描仪功能的集成感兴趣。
media
权限添加到清单中。@microsoft/teams-js
库。在运行这个应用程序时,我会看到下面这个错误:
ReferenceError:未在对象处定义窗口。(/Users/dch/Desktop/GitHub/MedxNote/DCH/medxtasks-extension-api/node_modules/@microsoft/teams-js/dist/MicrosoftTeams.min.js:1:227)
在扩展应用中使用API可行吗?
或者,我是否必须在web应用程序中运行API (角)并在扩展中使用TaskModule中的API?
而且,没有在Docs女士中找到任何示例应用程序。
编辑:
我在实现后的问题是,这个API的用例是什么,这个API有什么特别之处,,因为在任何webapp中,它似乎都是一个普通的条形码。
发布于 2021-09-16 23:14:41
通过实验,我成功地构建了集成QR或条码扫描器在MS扩展中的解决方案。
我用的方法是,
Task module WebView
中提供应用程序的端点。清单更新:
"devicePermissions": [
"media",
],
角应用程序:
import { Component, OnInit } from '@angular/core';
import * as microsoftTeams from '@microsoft/teams-js';
@Component({
selector: 'app-qr-scanner',
templateUrl: './qr-scanner.component.html',
styleUrls: ['./qr-scanner.component.sass'],
})
export class QrScannerComponent implements OnInit {
constructor() {}
displayText = '';
result = '';
config: microsoftTeams.media.BarCodeConfig = {
timeOutIntervalInSec: 30,
};
ngOnInit(): void {
microsoftTeams.initialize();
}
onClick() {
microsoftTeams.media.scanBarCode((error: microsoftTeams.SdkError, decodedText: string) => {
if (error) {
if (error.message) {
console.log(' ErrorCode: ' + error.errorCode + error.message);
} else {
console.log(' ErrorCode: ' + error.errorCode);
}
this.displayText = error.message;
} else if (decodedText) {
this.displayText = decodedText;
console.log(decodedText);
}
}, this.config);
}
showResult() {
this.result = this.displayText;
}
}
<div style="margin: 10px">
<div>
<button (click)="onClick()" class="btn-cm" style="color: #58ef47; margin: 2px">Scan the Code</button>
</div>
<div>
<button (click)="showResult()" class="btn-cm" style="color: #58ef47; margin: 2px">Get Result</button>
</div>
</div>
<mat-label>{{ result }}</mat-label>
扩展应用程序(NodeJS):
....
return {
task: {
type: 'continue',
value: {
height: 600,
width: 600,
title: 'Task module WebView',
url: `https://example.com/qrscanner`
}
}
};
有关更多细节,请参阅Microsoft (集成QR或条形码扫描仪功能)的文档。
https://stackoverflow.com/questions/69210288
复制相似问题