涂煌豪
2022-04-19 7ee2437b006cfc30e940cfb1711bf42f2ca3553d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<aura:component implements="flexipage:availableForAllPageTypes" controller="BotController" >
 
    <aura:attribute name="question" type="String" default=""/>
    <aura:attribute name="messages" type="Object[]"/>
    <aura:attribute name="session" type="Array"/>
    <aura:attribute name="height" type="String" default="500px"/>
    <aura:attribute name="files" type="Object[]"/>
 
    <div style="{#'height: '+v.height}" class="slds-p-vertical--x-small">
        <div aura:id="content" class="content">
            <aura:iteration items="{!v.messages}" var="message">
 
                <lightning:layout >
                    <lightning:layoutitem padding="around-small">
                        <lightning:icon iconName="{#message.author == 'Me' ? 'standard:avatar_loading' : 'standard:custom_notification'}" size="small"/>
                    </lightning:layoutitem>
                    
                    <lightning:layoutitem padding="around-small" flexibility="grow">
                        <p><strong>{#message.author}</strong></p>
                        <p class="slds-text-body">{#message.messageText}</p>
                        
                        <aura:if isTrue="{!message.imageURL}">
                            <figure class="slds-image slds-image--card slds-m-top--x-small">
                                <img src='{#message.imageURL}'/>
                            </figure>
                        </aura:if>
                        
                        <aura:iteration items="{!message.buttons}" var="button">
                            <lightning:button label="{#button.label}" name="{#button.value}" onclick="{!c.postbackButtonClickHandler}" class="message-button"/>
                        </aura:iteration>
                        
                        <aura:iteration items="{!message.records}" var="record">
                            <dl class="slds-list--horizontal slds-wrap">
                                <aura:iteration items="{!record.fields}" var="field">
                                    <dt class="slds-item--label slds-text-color--weak slds-truncate">{!field.name}:</dt>
                                    <dd class="slds-item--detail slds-truncate">
                                        <aura:if isTrue="{!field.linkURL}">
                                            <a href="{#field.linkURL}">{#field.value}</a>
                                            <aura:set attribute="else">
                                                {#field.value}
                                            </aura:set>
                                        </aura:if>
                                    </dd>
                                </aura:iteration>
                            </dl>
                        </aura:iteration>
                        
                        <aura:iteration items="{!message.items}" var="item">
                            <aura:if isTrue="{!item.linkURL}">
                                <div class="list-item"><a href="{#item.linkURL}" target="_blank">{#item.name}</a></div>
                                <aura:set attribute="else">
                                    <div class="list-item">{#item.name}</div>
                                </aura:set>
                            </aura:if>
                        </aura:iteration>
                        
                    </lightning:layoutitem>
                </lightning:layout>
                
            </aura:iteration>
 
        </div>            
 
        <div class="footer slds-form-element slds-p-horizontal--x-small">
            <div class="slds-form-element__control">
                <input aura:id="utterance" type="text" class="slds-input" placeholder="Ask DreamBot..." onkeypress="{!c.utteranceHandler}" />
                <lightning:input aura:id="fileInput" 
                                 type="file" name="file" 
                                 multiple="false" 
                                 accept="image/*;capture=camera" 
                                 files="{!v.files}"
                                 onchange="{!c.uploadFile}"
                                  label="Select a file"/>
 
            </div>
        </div>            
 
    </div>
 
</aura:component>