第三方設定程式 UI 元件 JavaScript 檔案
每個元件都有 JavaScript 檔案。針對第三方組態器 UI 元件,此檔案包含傳送和接收資料以及與組態器互動的所有邏輯。
必要版本
| 適用於:Lightning Experience |
| 提供版本:具有 Revenue Cloud Growth 授權或 Revenue Cloud Advanced 授權的 Revenue Cloud Enterprise、Performance、Unlimited 及 Developer Edition |
此 JavaScript 範例使用 Lightning Message Service 事件來傳送和接收資料。
import {api, LightningElement} from 'lwc';
import {MessageContext, publish} from 'lightning/messageService';
import CONFIGR_CHANNEL from "@salesforce/messageChannel/lightning__productConfigurator_notification";
const LMS_EVENTS = Object.freeze({
VALUE_CHANGE: "valueChanged",
NAVIGATE: "navigate",
CLOSE_PREVIEW: "closePreview",
TOGGLE_INSTANT_PRICING: "toggleInstantPricing",
TOGGLE_RULES_VALIDATION: "toggleRulesValidation",
TOGGLE_COMPACT_LAYOUT: "toggleCompactLayout",
UPDATE_PRICES: "updatePrices",
VALIDATE_PRODUCT: "validateProduct",
CLONE_ITEMS: "cloneItems",
});
export const STATE_FIELDS = Object.freeze({
IS_SELECTED: "isSelected",
QUANTITY: "Quantity",
ATTRIBUTE_FIELD: "AttributeField",
PRODUCT_SELLING_MODEL: "ProductSellingModel",
PRICING_TERM_UNIT: "PricingTermUnit",
SUBSCRIPTION_TERM: "SubscriptionTerm",
SELLING_MODEL_TYPE: "SellingModelType",
PRICE_BOOK_ENTRY: "PricebookEntry",
IS_DELETED: "Deleted",
UNIT_PRICE: "UnitPrice",
CUSTOM_PRODUCT_NAME: "CustomProductName"
});
export default class MyComponent extends LightningElement {
@api transactionId;
@api transactionLineId;
@api currentTransactionLineId;
@api parentName;
@api origin;
@api messages;
@api header;
@api optionGroups;
@api summary;
@api navigationRoute;
@api searchInfo;
@api currencyCode;
@api transactionRecord;
@api headerTitle;
@api isDesignTime;
// ... do @api annotations for each of the input properties you want from
// Data Manager
subscription = null; // Stores the subscription to the message service
// Lifecycle hook that subscribes to the message channel when the component is initialized
connectedCallback() {
this.subscribeToMessageChannel();
}
// Subscribes to the Lightning Message Service channel to receive message
subscribeToMessageChannel() {
if (!this.subscription) {
this.subscription = subscribe(
this.messageContext,
CONFIGR_CHANNEL,
(message) => this.handleMessage(message)
);
}
}
handleMessage(message) {}
// Send the message to LMS
sendMessageToDataManager() {
const bulkMessagePayload = {
action: LMS_EVENTS.VALUE_CHANGE,
data: [
// Change 1: update the root product's quantity field
{
key: ["0QLxx0000004jGGGAY"],
field: STATE_FIELDS.QUANTITY,
value: 100
},
// Change 2: update the root product's attribute
{
key: ["0QLxx0000004jGGGAY"],
field: STATE_FIELDS.ATTRIBUTE_FIELD,
attributeId: "0tjxx0000000001AAA",
value: "New Value"
},
// Change 3: update another one of root product's attributes
{
key: ["0QLxx0000004jGGGAY"],
field: STATE_FIELDS.ATTRIBUTE_FIELD,
attributeId: "0tjxx0000000001AAB",
value: "0xxxx0000000001AAB"
},
// Change 4: create a picklist attribute that does not exist (non-defaulted picklist)
{
key: ["0QLxx0000004jGGGAY"],
field: STATE_FIELDS.ATTRIBUTE_FIELD,
attributeId: "0tjxx0000000001AAC",
value: "0xxxx0000000001AAB"
},
// Change 5: select a static child product
{
key: ["0QLxx0000004jGGGAY"],
productRelatedComponentId: '0dSxx00000000XtEAI', // the static child PRC to select
field: STATE_FIELDS.IS_SELECTED,
value: true
},
// Change 6: select a dynamic option with a child option below it
{
field: STATE_FIELDS.IS_SELECTED,
selectedDynamicOptions: dynamicOptionsForInputPayload,
productRelatedComponent: prcForInputPayload
},
// Change 7: change the PSM for the root product from onetime to termed
{
key: ["0QLxx0000004jGGGAY"],
field: STATE_FIELDS.PRODUCT_SELLING_MODEL,
value: {
psmId: "0jPxx00000002JZEAX",
pbeId: "01uxx000000A0tKAAX"
}
},
// Change 8: deselect a child static option
{
key: ["0QLxx0000004jGGGAY", '0QLxx0000004jGHGAY'],
field: STATE_FIELDS.IS_SELECTED,
value: false
}
]
};
publish(MessageContext, CONFIGR_CHANNEL, bulkMessagePayload);
}
}
- 適用於第三方設定程式 UI 元件的 Lightning 訊息服務
使用 Lightning Message Service (LMS) 事件,讓第三方元件能夠與產品組態流程中的「資料管理員」元件通訊。將 LMS 事件新增至元件的 JavaScript 檔案,以傳送和接收資料。
另請參照:
此文章是否解決您的問題?
請讓我們知道,以便我們改進!

