<template>
    <el-card> 打开源代码结合控制台查看 </el-card>
</template>

<script setup lang="jsx">
import { ref } from 'vue';
import { url, generateUUID, array } from '@/utils/tools';

defineOptions({
    name: 'DemoTools',
});

// url相关工具函数
const objToUrlParma = url.objToUrlParma({ x: 1, y: 2, z: 3, test: 'test' }, ['y']);
console.log('将对象转为链接上的参数', objToUrlParma);
//?x=1&z=3&test=test

const getUrlToParams = url.getUrlToParams(
    'https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_9333493271659511895%22%7D&n_type=-1&p_from=-1'
);
console.log('将链接上的参数转为对象', getUrlToParams);
// {
//     "context": "{\"nid\":\"news_9333493271659511895\"}",   //请注意，这里不会递归处理
//     "n_type": "-1",
//     "p_from": "-1"
// }

console.log('生成随机uuid', generateUUID());

console.group('两个array比较是否相等，只比较值，不比较顺序，不比较引用');
console.log(array.arraysAreEqual([1, 2, 3], [3, 2, 1]));
console.log(array.arraysAreEqual([1, 2, 3], [1, 2, 3]));
console.log(
    array.arraysAreEqual(
        [
            { a: 1, b: 2 },
            { c: 3, d: 4 },
        ],
        [
            { a: 1, b: 2 },
            { c: 3, d: 4 },
        ]
    )
);
console.log(
    array.arraysAreEqual(
        [
            { a: 1, b: 2 },
            { c: 3, d: 4 },
        ],
        [
            { a: 1, b: 2 },
            { c: 3, d: 5 },
        ]
    )
);
console.log(
    array.arraysAreEqual(
        [
            { a: 1, b: { b1: 1 } },
            { c: 3, d: 4 },
        ],
        [
            { a: 1, b: { b1: 1 } },
            { c: 3, d: 4 },
        ]
    )
);
console.log(array.arraysAreEqual([{ a: 1, b: 2, time: '09:00' }], [{ a: 1, b: 2, time: '10:00' }], ['time']));
console.groupEnd();
</script>

<style lang="scss" scoped></style>
