share-window.qml 3.7 KB
Newer Older
P
peterq 已提交
1 2 3 4 5 6 7 8 9 10
import QtQuick 2.0
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../js/app.js" as App
import "../js/util.js" as Util
import "../widget"

Window {
    id: window
P
peterq 已提交
11 12
    flags: Qt.MSWindowsFixedSizeDialogHint | Qt.WindowTitleHint | Qt.WindowCloseButtonHint
           | Qt.WindowModal | Qt.Dialog
P
peterq 已提交
13 14 15 16 17 18 19 20 21 22
    modality: Qt.ApplicationModal
    title: '分享到资源广场'
    minimumHeight: height
    minimumWidth: width
    maximumHeight: height
    maximumWidth: width
    visible: true
    width: 550
    height: 300

P
peterq 已提交
23
    property bool submitting: false
P
peterq 已提交
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    property var sliceMd5Promise
    property var meta
    property var timeMap: {
        "永久": 365,
        "7天": 7,
        "一个月": 30
    }
    property string fileExtention

    Component.onCompleted: {
        getSliceMd5()
    }

    function getSliceMd5() {
        sliceMd5Promise = Util.callGoAsync('pan.rapid.md5', {
                                               "fid": meta.fs_id
                                           }).then(function (sliceMd5) {
                                               console.log('slice md5',
                                                           sliceMd5)
                                               return sliceMd5
                                           })
        sliceMd5Promise.catch(function () {
            sliceMd5Promise = null
        })
    }

    TopIndicator {
        id: topIndicator
        z: 2
    }

    GridLayout {
        columns: 2
        width: parent.width - 20
        y: 20
        rowSpacing: 10
        anchors.horizontalCenter: parent.horizontalCenter
        Label {
            text: '分享文件名'
            width: parent.width * 30
            Layout.alignment: Qt.AlignRight
        }
        TextField {
            id: titleInput
            enabled: !window.submitting
            width: parent.width * 60
            placeholderText: "文件名"
            Component.onCompleted: {
                var t = meta.server_filename.split('.')
                window.fileExtention = t.pop()
                text = t.join('.')
            }
        }
        Label {
            text: '有效期'
            width: parent.width * 30
            Layout.alignment: Qt.AlignRight
        }
        ComboBox {
            id: selectDuraion
            enabled: !window.submitting
            model: Object.keys(window.timeMap)
        }

        Label {
        }
        Button {
            id: btnShare
            text: window.submitting ? '请稍后' : '分享'
            enabled: !submitting
            onClicked: {
                if (!titleInput.text)
                    return
                if (!sliceMd5Promise) {
                    getSliceMd5()
                }
                window.submitting = true
                sliceMd5Promise.then(function (sliceMd5) {
                    return Util.api('share', {
                                        "md5": window.meta.md5,
                                        "sliceMd5": sliceMd5,
                                        "title": titleInput.text + '.' + window.fileExtention,
                                        "duration": window.timeMap[selectDuraion.currentText],
                                        "fileSize": window.meta.size
                                    })
                })
                .then(function() {
                    topIndicator.success('分享成功')
P
peterq 已提交
112
                    return Util.sleep(1000)
P
peterq 已提交
113 114 115 116 117 118 119 120 121 122 123 124
                })
                .then(function(){
                    window.visible = false
                })
                .catch(function (err) {
                    topIndicator.fail(err.message)
                    window.submitting = false
                })
            }
        }
    }
}