import {fetch} from '@core/component//httpClient';
import Modal from '@core/component/modal';
export function getByteLen(val) {
    var len = 0
    for (var i = 0; i < val.length; i++) {
        var a = val.charAt(i)
        if (a.match(/[^\x00-\xff]/gi) != null) {
            len += 2
        } else {
            len += 1
        }
    }
    return len
}
export function getFormData($form) {
    var unindexed_array = $form.serializeArray()
    var indexed_array = {}
    $.map(unindexed_array, function (n, i) {
        indexed_array[n['name']] = n['value']
    })
    return indexed_array
}
export async function send({ basePath, url, query, showTip = true }) {
    let param = {
		basePath: basePath || '',
        url: url || '',
        method: 'POST',
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        xhrFields: {
            withCredentials: true,
        },
        data: JSON.stringify(
            query instanceof Array ? [...query] : { ...query },
        ),
    }
    if (!showTip) {
        param.errorHandler = (data, clearErrorTip) => {}
    }
    let res = await fetch(param)
    if (res.code !== 0) {
        var err = new Error(res.message)
        err.messages = res.messages || '接口出错'
        if (showTip) {
            Message.error(err.message)
        }
        throw err
    }
    return res
}
export function getEditUrl(item) {
    let editorUrl = ''
    switch (item.platformId) {
        case '1':
            editorUrl = `/editor/sale/pc?appId=${item.appId}&pageInstanceId=${item.pageId}&prototypeId=`
            break
        case '2':
        case '10':
        case '24':
            editorUrl = `/editor/sale/m?mobileProjectId=${item.appId}&mobilePageId=${item.pageId}`
            break
        case '3':
            editorUrl = `/editor/shop/pc?appId=${item.appId}&pageInstanceId=${item.pageId}&prototypeId=`
            break
        case '4':
        case '19': 
        case '32': 
        case '33': 
            editorUrl = `/editor/shop/m?mobileProjectId=${item.appId}`
            break
        case '35': 
            editorUrl = `/editor/sale/m?mobileProjectId=${item.appId}&mobilePageId=${item.pageId}&appType=15`
            break
        case '-1': 
            editorUrl = `/task?projectId=${item.pageId}`
            break
        default:
    }
    return editorUrl
}