wangzhibo
4 天以前 10595d8632f959d0954d1939243196f4eed02372
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
81
82
83
84
85
<template>
    <view class="tools-fn">
        <cl-row>
            <cl-col :span="6">
                <view class="item" @tap="chooseImage('album')">
                    <view class="icon">
                        <image src="/uni_modules/cool-cs/static/fn-pic.png" mode="aspectFit" />
                    </view>
                    <text>相册</text>
                </view>
            </cl-col>
 
            <cl-col :span="6">
                <view class="item" @tap="chooseImage('camera')">
                    <view class="icon">
                        <image src="/uni_modules/cool-cs/static/fn-camera.png" mode="aspectFit" />
                    </view>
                    <text>拍摄</text>
                </view>
            </cl-col>
        </cl-row>
    </view>
</template>
 
<script setup lang="ts">
import { useSocket, useTools } from "../../hooks";
import { useUpload } from "/@/cool";
 
const tools = useTools();
const { upload } = useUpload();
const socket = useSocket();
 
// 选择
function chooseImage(type: string) {
    uni.chooseImage({
        sourceType: [type],
        success(res) {
            (res.tempFiles as any[]).forEach(async (e) => {
                const url = await upload(e);
 
                socket.send({
                    type: "image",
                    data: url,
                });
            });
        },
    });
    tools.close();
}
</script>
 
<style lang="scss" scoped>
.tools-fn {
    padding: 20rpx;
 
    .item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        margin: 20rpx 0;
 
        .icon {
            height: 130rpx;
            width: 130rpx;
            background-color: #fff;
            border-radius: 16rpx;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 20rpx;
 
            image {
                height: 60rpx;
                width: 60rpx;
            }
        }
 
        text {
            font-size: 26rpx;
            color: #666;
        }
    }
}
</style>