PageSourceSearch

https://51aw.com/usr/plugins/ai/js/user.js?v=16

js 51aw.com collected 2026-10-04 03:50:37 UTC 16,054 bytes, 430 lines download raw bytes

1// js 模块开发代码示例(按功能闭包分割)
2;(async function (doc, win) {
3    // 登陆处理
4    const onLogin = () => {
5        // 校验用户名
6        const checkUsername = () => {
7            // 1.获取用户名的值
8            var username = document.getElementById("username")?.value
9            // 2.定义正则表达式
10            var reg_username = /^.{6,12}$/
11            // 3.判断值是否符合表达式的规则
12            var flag = reg_username.test(username)
13            var s_username = document.getElementById("s_username")
14            if (!flag) {
15                s_username.innerHTML = "用户名6-12位字符"
16                return false
17            } else {
18                s_username.innerHTML = ""
19                return username
20            }
21        }
22
23        // 校验密码
24        const checkPassword = () => {
25            var password = document.getElementById("password")?.value
26            var reg_password = /^.{6,12}$/
27            var flag = reg_password.test(password)
28            var s_password = document.getElementById("s_password")
29            if (!flag) {
30                s_password.innerHTML = "密码6-12位字符"
31                return false
32            } else {
33                s_password.innerHTML = ""
34                return password
35            }
36        }
37
38        function handleLoginEvent(e) {
39            const el = e.target.closest(".side-toolbar-login-authz");
40            if (!el) return;
41
42            if (!$UserManager.isLogin()) {
43                e.preventDefault();
44                win.$WinOpen({
45                    event: "open",
46                    datas: { key: "LOGIN", url: `/ai/login/` }
47                });
48            }
49        }
50
51        // 绑定事件
52        document.addEventListener("click", handleLoginEvent);
53        document.addEventListener("touchend", handleLoginEvent);
54
55        // 事件处理
56        doc.addEventListener("click", function (e) {
57            // 弹出
58            e.target.closest(".side-toolbar-login-settings") && win.$WinOpen({
59                event: "open",
60                datas: { key: "LOGIN", url: `/ai/login/` }
61            })
62
63            // 关闭
64            e.target.closest(".side-toolbar-login-close") && win.$WinOpen({
65                event: "close",
66                datas: { key: "LOGIN" }
67            })
68
69            // 登陆
70            if (e.target.closest(".side-toolbar-login-submit")) {
71                const account = $("#account").parsley()
72                const password = $("#password").parsley()
73                const accountVal = account.$element.val().trim()
74                const passwordVal = password.$element.val().trim()
75                account.$element.val(accountVal)
76                password.$element.val(passwordVal)
77
78                const aOk = account.validate() === true
79                const pOk = password.validate() === true
80                if (!aOk || !pOk) return
81
82                const id = e.currentTarget.id
83                console.log("验证通过", id, accountVal, passwordVal)
84
85                // 接口请求
86                $Http({
87                    method: "POST",
88                    url: "/api/account/loginByPassword",
89                    data: {
90                        username: accountVal,
91                        password: passwordVal
92                    }
93                }).then(e => {
94                    console.log("@响应数据", e)
95                    const { data, status, msg } = e
96                    if (status === 1) {
97                        // 存贮Token
98                        $LocalStorage.set("__token__", data)
99
100                        // 成功提示
101                        $Alert(msg || "登录成功")
102
103                        // 登录表单在 iframe 中,须同步顶层窗口的 $UserStore;非 iframe 场景下 top 即自身
104                        const um = (win.top && win.top.$UserManager) ? win.top.$UserManager : $UserManager;
105                        um.notifyChanged().finally(() => {
106                            win.$WinOpen({
107                                event: "close",
108                                datas: { key: "LOGIN" }
109                            })
110                        })
111                    } else {
112                        $Alert(msg || "登陆失败")
113                    }
114                })
115            }
116
117            // 注册
118            if (e.target.closest(".side-toolbar-register-submit")) {
119                const account = $("#account").parsley()
120                const password = $("#password").parsley()
121                const accountVal = account.$element.val().trim()
122                const passwordVal = password.$element.val().trim()
123                account.$element.val(accountVal)
124                password.$element.val(passwordVal)
125
126                const aOk = account.validate() === true
127                const pOk = password.validate() === true
128                if (!aOk || !pOk) return
129
130                const id = e.currentTarget.id
131                console.log("验证通过", id, accountVal, passwordVal)
132
133                // 注册前重新生成 oauth_id:让新账号绑定全新 IM 身份,不复用本机上一个用户残留的 ___USER__OAUTHID。
134                // 本帧 $Oauth 供本次注册请求用,顶层 $Oauth 供顶层页 IM 用(reset 会写入共享 localStorage)。
135                try {
136                    win.$Oauth && win.$Oauth.reset && win.$Oauth.reset()
137                    if (win.top && win.top.$Oauth && win.top.$Oauth !== win.$Oauth) win.top.$Oauth.reset()
138                } catch (err) {
139                    console.warn("[user] 注册前重新生成 oauth_id 失败", err)
140                }
141
142                // 接口请求
143                $Http({
144                    method: "POST",
145                    url: "/api/account/registerByPassword",
146                    data: {
147                        username: accountVal,
148                        password: passwordVal
149                    }
150                }).then(e => {
151                    console.log("@响应数据", e)
152                    const { data, status, msg } = e
153                    if (status === 1) {
154                        // 存贮Token
155                        $LocalStorage.set("__token__", data)
156
157                        // 成功提示
158                        $Alert(msg || "注册成功")
159
160                        // 注册表单在 iframe 中,须同步顶层窗口的 $UserStore
161                        const um = (win.top && win.top.$UserManager) ? win.top.$UserManager : $UserManager;
162                        um.notifyChanged().finally(() => {
163                            win.$WinOpen({
164                                event: "close",
165                                datas: { key: "LOGIN" }
166                            })
167                        })
168                    } else {
169                        $Alert(msg || "注册失败")
170                    }
171                })
172            }
173
174            // 退出
175            if (e.target.closest(".side-toolbar-logout-submit")) {
176                $UserManager.logOut()
177            }
178        })
179    }
180
181    // 用户菜单
182    const onNavMenu = () => {
183        // 1) 头像/触发按钮:就近操作同层兄弟 .user_menu(不要求紧邻)
184        $(document)
185            .off("click.userMenu", ".user_target")
186            .on("click.userMenu", ".user_target", function (e) {
187                e.stopPropagation()
188                e.preventDefault()
189                // 未登录打开登录弹窗
190                if (!$UserManager.isLogin()) {
191                    win.$WinOpen({
192                        event: "open",
193                        datas: { key: "LOGIN", url: `/ai/login/` }
194                    });
195                    return
196                }
197
198                const $menu = $(this).parent().children(".user_menu") // 普通兄弟
199                $(".user_menu.is-open").not($menu).removeClass("is-open") // 先关其它
200                $menu.toggleClass("is-open")
201            })
202
203        // 2) 点击菜单项关闭当前菜单
204        $(document)
205            .off("click.userMenu", ".user_menu a")
206            .on("click.userMenu", ".user_menu a", function () {
207                $(this).closest(".user_menu").removeClass("is-open")
208            })
209
210        // 3) 登录按钮
211        $(document)
212            .off("click.userMenu", ".user_menu .login_btn")
213            .on("click.userMenu", ".user_menu .login_btn", function (e) {
214                e.stopPropagation()
215                $(".login_dialog").show()
216                $(this).closest(".user_menu").removeClass("is-open")
217            })
218
219        // 4) 退出按钮
220        $(document)
221            .off("click.userMenu", ".user_menu .logout_btn")
222            .on("click.userMenu", ".user_menu .logout_btn", function (e) {
223                e.stopPropagation()
224                $(this).closest(".user_menu").removeClass("is-open")
225                // TODO: 调用退出接口
226            })
227
228        // 5) 点击空白处关闭
229        $(document)
230            .off("click.userMenuBlank")
231            .on("click.userMenuBlank", function (e) {
232                if (!$(e.target).closest(".user_target, .user_menu").length) {
233                    $(".user_menu").removeClass("is-open")
234                }
235            })
236    }
237
238    // 用户状态
239    const onUserMian = () => Launcher({
240        container: "ai-navigation-container",
241    })
242
243    // 充值中心(page)
244    const onLoadUserRecharge = () => Launcher({
245        container: "ai-user-recharge-container",
246        data() {
247            return {
248                isVip: false,
249                userCoins: 0,
250                user_recharge_configs: [],
251                curr_recharge_product: {},
252                curr_recharge_payment: {},
253            }
254        },
255        // 函数定义
256        methods: {
257            // 充值配置
258            onLoadRechargeMain() {
259                const _this = this;
260
261                // 
262                $MessageLoading("加载中...")
263
264                // 接口请求
265                $Http({
266                    url: "/api/order/goodsList",
267                    data: {
268                        type: 2
269                    }
270                }).then((e)=> {
271                    const { data, status, msg, isVip } = e;
272                    if (status === 1 && data?.product?.[0].pay?.length) {
273                        _this.isVip = isVip;
274                        _this.user_recharge_configs = data;
275                        _this.curr_recharge_product = data.product[0];
276                        _this.curr_recharge_payment = data.product[0].pay[0];
277                    }
278                }).catch((error) => {
279                    console.error('处理错误:', error);
280                }).finally(() => {
281                    $MessageClose()
282                });
283            },
284
285            // 渠道选择
286            onChangeProduct(e) {
287                const _this = this;
288                if (e?.pay?.length) {
289                    _this.curr_recharge_product = e;
290                    _this.curr_recharge_payment = e.pay[0];
291                }
292            },
293
294            // 支付选择
295            onChangePayment(e) {
296                const _this = this;
297                _this.curr_recharge_payment = e;
298            },
299
300            // 支付提交
301            onPay() {
302                const _this = this;
303                if(!(_this.curr_recharge_product?.id && _this.curr_recharge_payment?.channel)) {
304                    $Alert("请选择支付方式")
305                    return;
306                }
307
308                $MessageLoading()
309
310                $Http({
311                    method: "POST",
312                    url: "/api/order/createPaying",
313                    data: {
314                        pay_type: _this.user_recharge_configs.channel[0].name,
315                        product_id: _this.curr_recharge_product.id,
316                        pay_way: _this.curr_recharge_payment.channel
317,
318                    }
319                }).then(e => {
320                    $MessageClose()
321                    const { data, status, msg } = e
322                    if (data?.payUrl) {
323                        $ShowConfirmDialog({
324                            title: '支付确认',
325                            message: '是否支付成功? 请点击确认',
326                            cancelButtonText: "关闭",
327                            closeable: true
328                        }).then(() => {
329                            // _this.onLoadRechargeMain();
330                            location.reload();
331                        }).catch(() => {
332                            location.reload();
333                        });
334                        const link = document.createElement('a');
335                        link.href = `${data.payUrl}`;
336                        link.target = '_blank';
337                        link.rel = 'noopener noreferrer';
338                        document.body.appendChild(link);
339                        link.click();
340                    } else {
341                        $Alert(msg)
342                    }
343                })
344            },
345        },
346
347        // 启动入口
348        mounted() {
349            const _this = this
350            $UserManager.refresh().then(res => {
351                this.userCoins = res.money || 0
352            }); //更新用户金币信息
353            _this.onLoadRechargeMain();
354        }
355    })
356
357    // 金币明细(page)
358    const onLoadUserRechargeRecord = () => Launcher({
359        container: "ai-user-recharge-record-container",
360        data() {
361            return {
362                user_recharge_record_list: [],
363                pageOptions: {
364                    page: 1,
365                    limit: 10,
366                    total: 0
367                }
368            }
369        },
370        // 函数定义
371        methods: {
372            // 充值配置
373            onLoadUserRechargeRecordList() {
374                const _this = this;
375                $MessageLoading("加载中...")
376                const page = _this.pageOptions.page++
377                // 接口请求
378                $Http({
379                    url: "/api/order/pc_orderList",
380                    data: {
381                        page,
382                        limit: _this.pageOptions.limit,
383                        type: 2
384                    }
385                }).then((e)=> {
386                    const { data: { list = [], count = 0 }, status } = e
387                    console.log("@e", e);
388                    if (status === 1 && list?.length) {
389                        _this.user_recharge_record_list = list;
390                        _this.pageOptions.total = count;
391                        initPageNavigator(page, count, _this.pageOptions.limit, _this.onLoadUserRechargeRecordList)
392                    }
393                }).catch((error) => {
394                    console.error('处理错误:', error);
395                    $Alert(msg);
396                }).finally(() => {
397                    $MessageClose()
398                });
399            },
400        },
401        beforeDestroy() {
402            this.clip && this.clip.destroy();
403        },
404
405        // 启动入口
406        mounted() {
407            const _this = this
408            _this.onLoadUserRechargeRecordList();
409            this.$nextTick(() => {
410                this.clip = new ClipboardJS('.recharge_records_item_title');   // 这里面自动绑定 click(委托)
411                this.clip.on('success', e => { $Alert('复制成功'); e.clearSelection(); });
412                this.clip.on('error',   e => { $Alert('复制失败'); console.error(e); });
413            });
414        }
415    })
416
417    // #### 初始初始模块(初始化) #########################################
418	$LoadrManager.moduleExecutor({
419        // 全局处理
420		'all-funcs': () => { 
421            onUserMian(); 
422            onNavMenu(); 
423            onLogin() 
424        },
425		// 钱包充值(列表)
426		'ai-user-recharge': () => onLoadUserRecharge(),
427        // 钱包充值(记录)
428		'ai-user-recharge-record': () => onLoadUserRechargeRecord(),
429	});
430})(document, window)

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.