Files
yunzerwebsiteallinone/uniapp/api/contact.js
T

71 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 通讯录(移动端)接口封装。
* 对应后端 go/controllers/app_contact.go 的 /app/oa/contact/* 只读接口。
*/
import { request } from '@/api/request.js'
/** 联系人类型:1-内部员工 2-外部联系人 */
export const CONTACT_TYPE_OPTIONS = [
{ value: 1, label: '内部' },
{ value: 2, label: '外部' }
]
export function getContactTypeLabel(value) {
return Number(value) === 2 ? '外部' : '内部'
}
/**
* 多手机号格式化:JSON 数组 / 分隔符字符串 / 单个号码 → "138…、139…"(无内容返回空串)。
* 与 Web 管理端 contact/index.vue 的 formatMobiles 口径保持一致。
*/
export function formatMobiles(val) {
if (!val) return ''
let arr = []
if (Array.isArray(val)) {
arr = val
} else {
const s = String(val).trim()
if (!s) return ''
try {
const parsed = JSON.parse(s)
arr = Array.isArray(parsed) ? parsed : [s]
} catch (e) {
arr = s.split(/[,,、;;\s]+/)
}
}
return arr.map((m) => String(m || '').trim()).filter(Boolean).join('、')
}
/** 取联系人首选号码:优先 phone,其次 mobiles 中的第一个 */
export function primaryPhone(contact) {
if (!contact) return ''
const phone = String(contact.phone || '').trim()
if (phone) return phone
const first = formatMobiles(contact.mobiles)
return first ? first.split('、')[0] : ''
}
/** 分页查询通讯录 */
export async function fetchContacts(params = {}) {
const data = await request({
url: '/app/oa/contact/list',
data: {
page: params.page || 1,
pageSize: params.pageSize || 20,
keyword: params.keyword || '',
org_id: params.orgId || 0,
contact_type: params.contactType || 0
}
})
return { list: (data && data.list) || [], total: (data && data.total) || 0 }
}
/** 组织架构树(含各部门内部联系人数量) */
export function fetchContactOrgTree() {
return request({ url: '/app/oa/contact/org-tree' })
}
/** 联系人详情 */
export function getContact(id) {
return request({ url: `/app/oa/contact/${id}` })
}